I have strings in the following format e.g. 20110201 and I want to convert it to a date in delphi, then subtract it from today to get the number of days difference.
How can I do that?
Sorry for my english.
The functions you need are Copy (to retrieve parts of your input string), StrToInt (to convert the string parts to integers), DateUtils.EncodeDate (to create a TDate from the integers), Now (to retrieve the current date as TDate) and DateUtils.DaysBetween (to get the difference between two dates in days).
I think you can figure out the rest on your own using the Delphi help for these functions.
Use Copy to extract the 3 substrings for year, month, day. Then StrToInt to convert them into integers, then EncodeDate to turn the 3 integers into a TDateTime.
TDateTime is a float, counting whole days before the decimal point and the time at that day as the fraction after the decimal point.
In SysUtils there is a function called Date: TDateTime which returns the current date.
You can simply substract the TDateTime you parsed out of the string from the value returned by Date to get the number of days difference between them.
Related
The date is coming from an imported xml that gives a 13 digit string (unix epoch time format).
The following snippet causes the resulting column value to be set to 1970-01-01
seconds=msg.time_stamp_long.to_i/1000
time=Time.at(seconds).utc.to_s
msg.time_stamp=time
msg.save
How to get the correct format for a DateTime column?
Time.at(1663681609392 / 1000).to_datetime
or if it's a string
Time.at("1663681609392".to_i / 1000).to_datetime
Be aware that unix time is epoch UTC time. Time and DateTime can get tricky in Ruby and in Rails. Make sure you are getting the time you expect. You may need to look into methods like .in_time_zone
To use your variables from the question:
msg.update(time_stamp: Time.at(msg.time_stamp_long / 1000))
is all you really need. As Max pointed out the DB adapter will handle the rest. But when you go to display or manipulate dates/times in Rails you might want to look into Date, Time, TimeWithZone, DateTime, etc. to understand the options that are out there and how they apply to your use case.
I'm trying to convert a date into a week number, which should be simple, only it's giving back value. Instead of the week number, it says 16/01/1900 00:00:00.
I used =ISOWEEKNUM(C2) and =WEEKNUM(C2, 2) and I tried it without time and in different date formats as well.
Does somebody know how to fix this issue?
Issue is found, the cells of the week numbers had a date format, so I had to convert it into plain text. It works now!
I've read I can add timezone information on an ISO8601 date by appending for example Z or +02 or -03:00.
I've also read that I can add timespan information by appending a P and then the time, for example 4DT2H (4 days and two hours).
How can I combine the two? Timezone or timespan first?
E.g. 2018-10-18T14:20+02P1D vs 2018-10-18T14:20P1D+02
By having two values, you are basically describing when an event starts, and how long it lasts. Such values are covered in section 4.4.4.3 of the ISO 8601 specification, titled "Representations of time interval identified by start and duration".
The spec requires full compliance with the established formats for both the timestamp and the time period parts, separating them with a forward slash (/) character.
For example: 2018-10-18T14:20+02/P1D
The time zone offset (whether Z, or +02, or -03:00) belongs with the timestamp, before the slash.
That said, I know of few parsers that understand this format. It is compliant, but not every parser of ISO 8601 necessarily understands every part of the spec.
Does neo4j natively support data format for node properties? like for example url links (clickable), numbers (integer, float..), date (YYYY/MM/DD).
Or we need to programmatically convert property string to whatever format we need?
Property values in Neo4j could be either Java primitive types (float, double, int, boolean, byte,... ), Strings or array of both. Date objects as property values are not supported.
There are two ways to deal with days:
Store the date as msec since epoc, aka new Date().getTime() (in java)
pro: you can do calculations
pro: less memory/disc consumption as it's stored as a long
con: when just looking at the node, it's hard to infer the date without calculation
Store the date as a string using e.g. SimpleDateFormatter
pro: human readable
con: calculations are hard
Personally I tend to prefer the first one.
In case you need to store time + timezone, you can have two properties. One for the date in msecs based on UTC, another one for the timezone.
What is the standard way to present the ambiguous extra hour when winter time begins?
So far i used localized time formats to display and parse dates and times. E.g. 1. January 2014, 15:27.
I'm using location based time zones like "Europe/Berlin".
And i can't just change to plain GMT offsets because i do need to perform calculations on the dates. Otherwise i would get the wrong absolute time when moving across DST change dates.
All this works fine except for the one hour at the end of DST (e.g. October 26th 2014, 2am-3am) which occurs twice. I need to present it in a way that i can later parse again.
Is there a stadardized format? Do i just add a custom symbol? Do i use the GMT offset additionally to the geographic time zone? And how do i know when to use this special format - because i don't want to print it all the time, since it's redundant most of the year.
The answer by Matt Johnson is correct and insightful.
Java 8 & java.time.*
Let me add another to his list, from the new java.time.* classes bundled with Java 8 and defined by JSR 310. These new classes are inspired by Joda-Time but are re-architected.
The default used by java.time.ZonedDateTime is one concatenated string using square brackets around the time zone name and no spaces.
2014-10-26T13:49:48.278+01:00[Europe/Berlin]
#MattJohnson Feel free to merge this answer's content with yours if you wish.
There isn't a standard that combines everything. The closest you can get is with two fields. One which would be an ISO8601/RFC3339 Date+Time+Offset, and another which would be the IANA/Olson time zone.
Depending on your platform, you may have a single object that represents both, such as a DateTime in Joda-Time or a ZonedDateTime in Noda Time. But there is no standardized representation of this as a string.
Here are some that I have seen though:
Two completely separate strings:
"2014-10-26T02:00:00+01:00"
"Europe/Berlin"
One concatenated string, space separated:
"2014-10-26T02:00:00+01:00 Europe/Berlin"
One concatenated string with a space and using parentheses:
"2014-10-26T02:00:00+01:00 (Europe/Berlin)"
One concatenated string without any space, but with square brackets: (thanks Basil)
"2014-10-26T02:00:00+01:00[Europe/Berlin]"
As JSON, with some predetermined field names:
{
value: "2014-10-26T02:00:00+01:00",
zone: "Europe/Berlin"
}
As XML, with some predetermined attribute names:
<TimeStamp Value="2014-10-26T02:00:00+01:00" Zone="Europe/Berlin" />
As XML, with some predetermined element names:
<TimeStamp>
<Value>2014-10-26T02:00:00+01:00</Value>
<Zone>Europe/Berlin</Zone/>
</TimeStamp>
Any of these would be acceptable. Pick the one that fits your situation, or adapt to something similar.
Regarding your question:
... how do i know when to use this special format ...
When you're recording an event that has already passed and cannot be changed, then you do not need to store the time zone. The date+time+offset value alone is sufficient. Otherwise, you need both.