Time Zone issue

Hi,

I have a scenario where my Database is in GMT and I am trying to convert it to EST time by using GMT function  gmt(property(local!data,"XXX",{}),"EDT") its working fine during night time but when this function is executed during day time its giving current date-1.

Any solution for this would be really appreciated.

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Senior Developer
    in reply to Jagan c

    That is the main point to missed mentioning. todate() function treats the input as GMT. You should always have your custom expression rule to convert datetime to date.

    /*Converts Datetime to date based on passed user. If no user is passed loggedInUser will be considered
    */
    
    a!localVariables(
      local!user : if(
        rule!RWP_isNullOrEmpty(ri!user),
        loggedInUser(),
        ri!user
      ),
      local!timeZone : usertimezone(local!user),
      if(
        rule!RWP_isNullOrEmpty(ri!dateTime),
        ri!dateTime,
        todate(local(ri!dateTime, local!timeZone))
      )

  • 0
    A Score Level 2
    in reply to chanakyav0002

    I tried using the code provided still I am getting one date minus.

    The data in DB is

    and when try with the code provide it's giving me the below result

    We are using the below code as suggested.

    load(
    local!userTimeZone:usertimezone(loggedInUser()),
    if(rule!APN_isEmpty(ri!dateValue),"",todate(local(ri!dateValue,local!userTimeZone)))
    )

  • As a side note, I would recommend moving away from the use of load() and with() and migrating toward the newer a!localVariables() function for variable declarations.

    To clarify on the date situation here, are you trying to always use the exact date value of what is in the DB, or do you need to add an offset for timezone, which will change the date at certain times of the day?

    If you just want a straight date, try:

    if(
        rule!APN_isEmpty(ri!dateValue),
        "",
        date(
          year(ri!dateValue),
          month(ri!dateValue),
          day(ri!dateValue)
        )
    )