Store date in neo4j - neo4j

The given date format in CSV is '(Fri) 09 Jan 2018 (32)'. This should feed to database as a date column to allow order by date. How could convert above format to Neo4j date format at the insertion time ?

Solution
WITH '(Fri) 09 Jan 2018 (32)' as inputString
WITH split(inputString, ' ') as parts
WITH parts[1] + ' ' + parts[2] + ' ' + parts[3] AS concatDate
RETURN apoc.date.parse(concatDate, 's',"dd MMM yyyy") as date;
Explanation:
line 1: defines a date for testing purpose
line 2: splits the given date into its pieces at each blank
line 3: concatenates the day, month and year
line 4: parse the built date of line 3 and convert it to a Neo4j date
Result
╒══════════╕
│"date" │
╞══════════╡
│1515456000│
└──────────┘
Alternative solution
WITH '(Fri) 09 Jan 2018 (32)' as inputString
WITH split(inputString, ' ') as parts
WITH reduce(s = "", x IN parts[1..4] | s + x) AS concatDate
RETURN apoc.date.parse(concatDate, 's',"ddMMMyyyy") as date;

Assuming the date substring always starts at offset 6 in the input string, this will return the date offset from 01 Jan 1970, which is adequate for comparing dates:
WITH '(Fri) 09 Jan 2018 (32)' as s
RETURN apoc.date.parse(SUBSTRING(s, 6, 11), 'd', "dd MMM yyyy") as date;

Related

Subtracting datetime from google admin console logs

Google admin exports the following Date Time stamps which are not recognized by sheets. How can I get sheets to recognize these as date format? So, I can complete subtraction on them like "Feb 3, 2020, 2:00:29 PM GMT" minus "Feb 2, 2020, 1:00:09 PM GMT"
Workaround
I'll use these datetimes as example Feb 3, 2020, 2:00:29 PM GMT and Feb 2, 2020, 3:00:09 PM GMT
At the moment there's no sheet function which handles timezone so here's my approach:
First separate the days like so:
=TEXT(INDEX(SPLIT(A2, ","),1 ,1), "mmm d, ") & INDEX(SPLIT(A2, ","),1 ,2)
As well as the hours:
=SUBSTITUTE(INDEX(SPLIT(A5, ","), 1, 3), "GMT", "")
Then simply calculate the difference in hours:
Date difference in hours
=DATEVALUE(TEXT(INDEX(SPLIT(A2, ","),1 ,1), "mmm d, ") & INDEX(SPLIT(A2, ","),1 ,2)) -
DATEVALUE(TEXT(INDEX(SPLIT(B2, ","),1 ,1), "mmm d, ") & INDEX(SPLIT(B2, ","),1 ,2))
DATEVALUE Converts a provided date string in a known format to a date value which is a number that we can treat.
NOTE: DAYS function will treat leap years as well so you can use it instead of DATEVALUE difference
Hour difference
=TIMEVALUE(SUBSTITUTE(INDEX(SPLIT(A2, ","), 1, 3), "GMT", "")) -
TIMEVALUE(SUBSTITUTE(INDEX(SPLIT(B2, ","), 1, 3), "GMT", ""))
TIMEVALUE will return the fraction of a 24-hour day which can be negative, I won't use =ABS function because I want to add this value to the date difference, so in adding this negative value we'll make the real difference between 2 dates.
Once we have both values we simply add them in order to retrieve the difference in hours:
=( DATEVALUE(TEXT(INDEX(SPLIT(A2, ","),1 ,1), "mmm d, ") & INDEX(SPLIT(A2, ","),1 ,2)) -
DATEVALUE(TEXT(INDEX(SPLIT(B2, ","),1 ,1), "mmm d, ") & INDEX(SPLIT(B2, ","),1 ,2)) ) * 24
+
(TIMEVALUE(SUBSTITUTE(INDEX(SPLIT(A2, ","), 1, 3), "GMT", "")) -
TIMEVALUE(SUBSTITUTE(INDEX(SPLIT(B2, ","), 1, 3), "GMT", "")) ) * 24
And we can retrieve different formats like hours or minutes keeping in mind that DATEVALUE and TIMEVALUE have to be multiplied by 24.
References
TEXT
SPLIT
INDEX
SUBSTITUTE
TIMEVALUE
DATEVALUE
DAYS: not used in my approach but it's useful.

How to format a date range (with only one year string) in different locale's in iOS?

The date string in English: Jan 18 - Jan 26, 2018
Incorrect Korean date string: Jan 18 - 2018 Jan 26
What should happen in Korean: 2018 Jan 18 - Jan 26 (not exactly correct Korean, just referring to the location of the year. See accepted answer to see proper Korean date format)
Right now this requires to date formatters, but you have to hardcode which date formatter has the year, so the Korean date doesn't look right.
Is this possible to do in Swift/Objc without just putting the year string on both sides of the date range?
Use a DateIntervalFormatter:
let sd = Calendar.current.date(from: DateComponents(year: 2018, month: 1, day: 18))!
let ed = Calendar.current.date(from: DateComponents(year: 2018, month: 1, day: 26))!
let dif = DateIntervalFormatter()
dif.dateStyle = .medium
dif.timeStyle = .none
dif.locale = Locale(identifier: "en_US")
let resEN = dif.string(from: sd, to: ed)
dif.locale = Locale(identifier: "ko_KR")
let resKO = dif.string(from: sd, to: ed)
This results in:
Jan 18 – 26, 2018
2018. 1. 18. ~ 2018. 1. 26.
The output isn't exactly what you show in your question but the output is appropriate for the given locales.

Transforming date + time in a TimeStamp Object

I'm having some trouble with making a timestamp from a date and a time
What i'm trying to do:
date = "2016 2 21"
time = "03:00 UTC"
output = "Thu, 21 Feb 2016 03:00:00 UTC +00:00"
I'm getting the date from a form_for:
f.date_field(:date_first)
But I'm not sure of how should I pick up the time.
To give you a headstart:
dt = "2016-2-21"
time = "03:00 UTC"
dtime = DateTime.parse(dt + 'T' + time)
output = dtime.rfc2822
and the result is:
#=> "Sun, 21 Feb 2016 03:00:00 +0000"
Maybe you could do something like this
strftime("%d.%m.%Y. %H:%M:%S")
and also get your locale yml file from here
https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale

How to covert the date string range into datatime data type

I need to convert the following raw string (date range) into ruby datetime datetype.
How to finish it on Rails ?
raw string
"2014 April/July 24-1"
convert to ruby datetime variable
start_date = 2014-04-24
end_date = 2014-07-01
raw string
"2015 April 06-20"
convert to ruby datetime variable
start_date = 2015-04-06
end_date = 2015-04-20
This may help
# In order to generate
# year = 2014
# months = "April/July"
# days = "24-1"
/(?<year>\d{4})\s*(?<months>\w+\/\w+)\s*(?<days>\d{1,2}\-\d{1,2})/ =~ "2014 April/July 24-1"
date1 = "#{year} #{months.split('/')[0]} #{days.split('-')[0]}"
date2 = "#{year} #{months.split('/')[1]} #{days.split('-')[1]}"
start_date = Date.strptime(date1, "%Y %b %d") #=> Thu, 24 Apr 2014
end_date = Date.strptime(date2, "%Y %b %d") #=> Tue, 01 Jul 2014

Converting Date+Time Formats

I need to convert the following format into a new format using NSDateFormatter.
'Fri, 25 Mar 2011 10:16:00 -0700'.
I tried using "aaa, dd bbb YYYY HH:MM:SS ZHHMM" as format, but it doesn't work; it gives me a date way in the past.
I also need to convert it into the Eastern Time Zone when creating a new date.
The code I used is the following one:
NSDateFormatter *newDateFormatter = [[NSDateFormatter alloc] init];
[newDateFormatter setDateFormat:#"dd MMM YYYY HH:mm:SS"];
Let's break this string down into the various portions:
Fri, 25 Mar 2011 10:16:00 -0700 becomes:
Fri: abbreviated day of the week
25: potentially zero-padded day of the month
Mar: abbreviated month
2011: year
10: potentially zero-padded hour (in 24-hour format because there is no AM/PM)
16: potentially zero-padded minute
00: zero-padded second
-0700: time zone offset
Now let's look at the date format patterns that NSDateFormatter supports:
abbreviated day of the week: EEE
zero-padded day of the month: dd
abbreviated month: MMM
year: y
zero-padded hour (24-hour): HH
zero-padded minute: mm
zero-padded second: ss
time zone offset: ZZZ
Thus, your format string should be: #"EEE, dd MMM y HH:mm:ss ZZZ".

Resources