Google spreadsheet - how to determine timezone using function - timezone

How to use a formula to determine the current timezone?
The formula I use gives an unexpected result.
My spreadsheet settings (File > Spreadsheet settings...):
Time zone: (GMT+01:00) Amsterdam
The formula I used:
=TEXT(NOW(),"HH:mm z")
This gives:
12:47 GMT
Local clock time is 12:47, I would expect the formula to show: "12:47 GMT+1".
I also tried Z instead of z, which gives "12:47 +0000", I would expect +1.
Any suggestions?
I need this so I can determine UTC time and convert to Epoch time ("UTC time" - DATE(1970,1,1)*24*60*60)

You can't do that using formulas w/o javascript checking your local timezone.
As per this form:
https://docs.google.com/a/codeproject.com/spreadsheet/ccc?key=0AqhqY231XZd3cFBiY2VqeWdmNWdaX25zN2lpekthQlE&hl=en_US#gid=4
timezone formatting stuff is not supported in TEXT. This spreadsheet was done by one of Stackoverflow contributors, it is not mine.
So... script?

=TEXT( NOW()+x/24 , "DD/MM/YYYY HH:mm:ss" )
=TEXT( NOW()+8/24 , "DD/MM/YYYY HH:mm:ss" )
The (+x/24) after the NOW function will add x hours (in my case 8) to the standard time. NOW()+1 will give you the time tomorrow so working bakc or forward you can set the formula to give different time zones.
Hope this helps,
Robbie

Related

Converting text into a date not working in google sheets

I have a piece of text I need to transform into a date:
"12/28/20 10:44 PM"
Any of the usual tricks are not working to get sheets to recognize this as a date.
I've made progress parsing out the date and time into separate cells but it still won't factor in the AM PM part.
Is there a quick way to convert to a date for this type of format?
try:
=REGEXREPLACE(A1; "(\d+)\/(\d+)\/(\d+)"; "$2/$1/20$3")*1
then:

How to add AM/PM in googlesheet

Im having trouble adding AM/PM in my formula in google sheet
This is my formula
=IF(ISDATE(H7),TEXT(NOW(),"h:mm"),"nt")
If you seend the format of NOW() is h:mm that gives you time only like 10:00
Now how can I add AM/PM after h:mm
How about this modified formula?
Modified formula:
=IF(ISDATE(H7),TEXT(NOW(),"h:mm AM/PM"),"nt")
Official document says as follows.
AM/PM for displaying hours based on a 12-hour clock and showing AM or PM depending on the time of day.
When it's 2020/07/27 15:00:00, above formula returns 3:00 PM.
Reference:
TEXT

Date(timeIntervalSince1970:) returns 2 different results

I am getting some results from a weather API and one of that is date in epoch time stamp.
I found that converting with Date(timeIntervalSince1970:) I get the right date
I am using the specific number --> 1501452000 and I get 2 results on Playground
1) Jul 31,2017,12:00AM. -- when --> let date = Date(timeIntervalSince1970: 1501452000)
2) 2017-07-30 22:00:00 +0000 when --> print(date)
API results are :
"time_epoch": 1501452000,
"time": "2017-07-30 23:00",
By checking the rest of my results they are matching with the rest of the API results....... but when I convert 1501452000 -> to date I don't get the correct Hour 23:00 but 22:00 !
Any idea what is happening ?
is it wrong the API( I don't think so ) or the way I am converting it?
Thanks a lot
The timeIntervalSince1970 initializer sets up the time in the UTC timezone, while your API might be sending dates in GMT. When you are using print(data), you have different results, because if you are not using a DateFormatter to generate the String format of the Date object, it uses your devices current settings when formatting the Date object.
A Date object represents an absolute point in time, but when you are printing it with a DateFormatter, it gets converted into a location/time zone specific, relative representation. You just have to set up your DateFormatter to match the time zone settings of your API and you will see the dates correctly printed.
This issue happens on daylight saving times. Is your country changing daylight saving on this exact date?
let date = Date(timeIntervalSince1970: 1501452000) in Playgrounds should give you the time in your system's timezone when you see it on the right hand side.
When you print it and see 2017-07-30 22:00:00 +0000- this is the same timestamp in GMT
Is the API showing a particular time zone? It looks like GMT+1

How to write a query in Google Spreadsheet that returns date >= today?

I am writing the following =filter formula in Google spreadsheet:
=FILTER('Tab'!6:1963, ‘Tab’!E6:E1963 = "Major", ’Tab’!D6:D1963 > NOW())
Column D are dates and I am interested in including today. For instance today is the 7/19 and I would like to have the data that includes 7/19. My current formula returns values only from tomorrow (7/20). I tried the now()-1 but returned an #VALUE!.
Any help?
NOW() returns a datetime object (which includes the time). If you are comparing with a date, NOW() will (almost :) ) always be greater than the date alone (which would have a time component of 12:00 A.M., which is essentially 0).
Try using TODAY() to get the date only (adding/subtracting 1 will use tomorrow/yesterday, respectively).

Format times to display with 'AM/PM'

Normally, when I enter times in Google spreadsheet as 22:00:00 the display automatically switches to 10:00 PMbut sometimes it's not converting.
How can I set a common format for times in Google spreadsheet? I need this format: 8:00 PM.
Select all ranges that you wish to have this time format and go to Format > Number > More formats to select the one of your choice. (I think the one you want is near the bottom and shows as 3:59 PM.)
If you want to format a time with TEXT() to display with am/pm you can use:
=TEXT(DateField, "HAM/PM")
To get a results like
1am
1pm
10pm
12am
Use UPPER() to make it uppercase.

Resources