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.
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.
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
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
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".