I have written
1. gmt(now(),"IST")
2. local(now(),"IST")
local() function shows correct time as per local timestamp, but gmt is showing +1 hour in my current time. Anyone can explain why?
Discussion posts and replies are publicly visible
gmt function converts datetime into GMT and local function converts datatime into your profile timezone. gmt(now(),"IST") - gmt considers 1st parameter as datetime and 2nd parameter as its timezone. So as per here gmt takes now() datetime and IST as its timezone, converts into datetime with GMT timezone local(now(),"IST") - local considers 1st parameter as datetime and 2nd parameter as its timezone. So as per here gmt takes now() datetime and IST as its timezone, converts into datetime with your profile timezone
Here in both the cases even-though now() has its own timezone which is neglected as both gmt() & local() takes only datetime as first parameter
Hi Khemraj Soni,
The function gmt() is a date and time subtraction function. The function local() is a date and time addition function. Both functions take datetime as the first parameter and timezone as the second parameter. But the gmt() function subtracts the timezone offset from the datetime given as the first parameter and the local() function adds the timezone offset to the first parameter.
Lets say, if the now() returns 7/8/2018 11:46 AM GMT+05:30 and if we pass now() to gmt() and giving the timezone as IST, gmt(now(),"IST") will return 7/8/2018 6:16 AM GMT+05:30 since the timezone offset 5 hours and 30 minutes is subtracted from the given datetime.
If we pass now() to gmt() and giving the timezone as IST, local(now(),"IST") will return 7/8/2018 5:16 PM GMT+05:30 since the timezone offset is added to the given datetime.
Here notice the AM and PM appended with the output.
Hope this helps!