What is the difference between gmt() and local()?

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

Parents
  • 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!

Reply
  • 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!

Children