DT2UTC v1.05

AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
edited 2011-03-12 in Download section
DT2UTC
Function to returns the UTC date time from a DateTime field.

The datetime is stored in the database as Coordinated Universal Time (UTC). UTC is the international time standard (formerly Greenwich Mean Time, or GMT). Zero hours UTC is midnight at 0 degrees longitude. The datetime is always displayed as local time in Dynamics NAV. Local time is determined by the time zone regional settings used by your computer.
You must always enter datetimes as local time. When you enter a datetime as local time, it is converted to UTC using the current settings for the time zone and daylight saving time.

This function returns the UTC date time.

http://www.mibuso.com/dlinfo.asp?FileID=957

Discuss this download here.

Comments

  • Yaroslav_GaponovYaroslav_Gaponov Member Posts: 158
    Hi

    Some remark:

    I worked with function FORMAT(DT,0,9) in different version and know that parameter 9 exist begin form version NAV 3.70B

    Best Regards
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
    DT2UTC v1.01
    Function to returns the UTC date time from a DateTime field.

    The datetime is stored in the database as Coordinated Universal Time (UTC). UTC is the international time standard (formerly Greenwich Mean Time, or GMT). Zero hours UTC is midnight at 0 degrees longitude. The datetime is always displayed as local time in Dynamics NAV. Local time is determined by the time zone regional settings used by your computer.
    You must always enter datetimes as local time. When you enter a datetime as local time, it is converted to UTC using the current settings for the time zone and daylight saving time.

    This function returns the UTC date time.

    Version 1.01:
    Take care of blank dates

    http://www.mibuso.com/dlinfo.asp?FileID=957

    Discuss this download here.
  • ta5ta5 Member Posts: 1,164
    Hi Flemming
    Great work! Good idea to use xml-Format "9".

    Just 2 question to this:

    - I assume this function takes care of the current locale settings concerning daylight saving zone and dates. Is that correct?

    - What I don't understand is why currentdatetime returns just that (current date and time of the system) but if stored to a datetime field it is converted to utc. Is that correct, and do you know what could be the reason?

    Thanks again and thanks in advance for your comment to this.
    Thomas
  • FlemmingDKFlemmingDK Member Posts: 5
    Hi Thomas
    ta5 wrote:
    - I assume this function takes care of the current locale settings concerning daylight saving zone and dates. Is that correct?
    Yes, Navision/Dynamics NAV takes care of the current locale settings concerning daylight saving zone and dates.
    ta5 wrote:
    - What I don't understand is why currentdatetime returns just that (current date and time of the system) but if stored to a datetime field it is converted to utc. Is that correct, and do you know what could be the reason?
    If one company has users placed around the world, and they want a central log, then they have to log UTC date and time, otherwise the log will be mix-up if every user, was using they local time, and not a central time, when sorting on date time field.

    Flemming
    Best regards
    Flemming R. Petersen
    Denmark
  • ta5ta5 Member Posts: 1,164
    Thanks.
  • sanuychsanuych Member Posts: 4
    I don't understand what result we get in last statement of this code

    UTC_Text := FORMAT(DT,0,9);
    IF NOT EVALUATE(YYYY,COPYSTR(UTC_Text,1,4)) THEN
    EXIT(DT);
    IF EVALUATE(MM,COPYSTR(UTC_Text,6,2)) THEN
    EXIT(DT);
    IF EVALUATE(DD,COPYSTR(UTC_Text,9,2)) THEN
    EXIT(DT);
    D := DMY2DATE(DD,MM,YYYY);
  • ara3nara3n Member Posts: 9,256
    I think there is bug in this function
    IF EVALUATE(MM,COPYSTR(UTC_Text,6,2)) THEN
    EXIT(DT);
    IF EVALUATE(DD,COPYSTR(UTC_Text,9,2)) THEN
    EXIT(DT); 
    

    Should be
    IF NOT EVALUATE(MM,COPYSTR(UTC_Text,6,2)) THEN
    EXIT(DT);
    IF NOT EVALUATE(DD,COPYSTR(UTC_Text,9,2)) THEN
    EXIT(DT); 
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • FlemmingDKFlemmingDK Member Posts: 5
    ara3n wrote:
    I think there is bug in this function
    IF EVALUATE(MM,COPYSTR(UTC_Text,6,2)) THEN
    EXIT(DT);
    IF EVALUATE(DD,COPYSTR(UTC_Text,9,2)) THEN
    EXIT(DT); 
    

    Should be
    IF NOT EVALUATE(MM,COPYSTR(UTC_Text,6,2)) THEN
    EXIT(DT);
    IF NOT EVALUATE(DD,COPYSTR(UTC_Text,9,2)) THEN
    EXIT(DT); 
    

    You are totally right, new version 1.02 ready.
    Best regards
    Flemming R. Petersen
    Denmark
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
    DT2UTC v1.02
    Function to returns the UTC date time from a DateTime field.

    The datetime is stored in the database as Coordinated Universal Time (UTC). UTC is the international time standard (formerly Greenwich Mean Time, or GMT). Zero hours UTC is midnight at 0 degrees longitude. The datetime is always displayed as local time in Dynamics NAV. Local time is determined by the time zone regional settings used by your computer.
    You must always enter datetimes as local time. When you enter a datetime as local time, it is converted to UTC using the current settings for the time zone and daylight saving time.

    This function returns the UTC date time.

    Version 1.02:
    Fix bug Evaluate in version 1.01

    Version 1.01:
    Take care of blank dates

    http://www.mibuso.com/dlinfo.asp?FileID=957

    Discuss this download here.
  • ta5ta5 Member Posts: 1,164
    Hi Flemming
    Just a last question:
    You note that "You must always enter datetimes as local time". Is entering through a GUI and storing through a codeunit the same? And last but not least: If storing through a codeunit and reading againg thorugh a codeunit to a variable: what value is stored in the variable (local datetime or utc datetime)? Sorry, maybe a stupid question.
    Thanks anyway
    Thomas
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
    DT2UTC v1.03
    Function to returns the UTC date time from a DateTime field.

    The datetime is stored in the database as Coordinated Universal Time (UTC). UTC is the international time standard (formerly Greenwich Mean Time, or GMT). Zero hours UTC is midnight at 0 degrees longitude. The datetime is always displayed as local time in Dynamics NAV. Local time is determined by the time zone regional settings used by your computer.
    You must always enter datetimes as local time. When you enter a datetime as local time, it is converted to UTC using the current settings for the time zone and daylight saving time.

    This function returns the UTC date time.

    Version 1.03:
    New version 1.03 of DT2UTC, with 2 functions, DT2UTC and UTC2DT, now it is using settings from register DB to convert.

    Version 1.02:
    Fix bug Evaluate in version 1.01

    Version 1.01:
    Take care of blank dates

    http://www.mibuso.com/dlinfo.asp?FileID=957

    Discuss this download here.
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
    DT2UTC v1.04
    Function to returns the UTC date time from a DateTime field.

    The datetime is stored in the database as Coordinated Universal Time (UTC). UTC is the international time standard (formerly Greenwich Mean Time, or GMT). Zero hours UTC is midnight at 0 degrees longitude. The datetime is always displayed as local time in Dynamics NAV. Local time is determined by the time zone regional settings used by your computer.
    You must always enter datetimes as local time. When you enter a datetime as local time, it is converted to UTC using the current settings for the time zone and daylight saving time.

    This function returns the UTC date time.

    Version 1.04:
    Fix. date bug when passing midnight!

    Version 1.03:
    New version 1.03 of DT2UTC, with 2 functions, DT2UTC and UTC2DT, now it is using settings from register DB to convert.

    Version 1.02:
    Fix bug Evaluate in version 1.01

    Version 1.01:
    Take care of blank dates

    http://www.mibuso.com/dlinfo.asp?FileID=957

    Discuss this download here.
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
    DT2UTC v1.05
    Function to returns the UTC date time from a DateTime field.

    The datetime is stored in the database as Coordinated Universal Time (UTC). UTC is the international time standard (formerly Greenwich Mean Time, or GMT). Zero hours UTC is midnight at 0 degrees longitude. The datetime is always displayed as local time in Dynamics NAV. Local time is determined by the time zone regional settings used by your computer.
    You must always enter datetimes as local time. When you enter a datetime as local time, it is converted to UTC using the current settings for the time zone and daylight saving time.

    This function returns the UTC date time.

    Version 1.05:
    Fix. date bug.

    Version 1.04:
    Fix. date bug when passing midnight!

    Version 1.03:
    New version 1.03 of DT2UTC, with 2 functions, DT2UTC and UTC2DT, now it is using settings from register DB to convert.

    Version 1.02:
    Fix bug Evaluate in version 1.01

    Version 1.01:
    Take care of blank dates

    http://www.mibuso.com/dlinfo.asp?FileID=957

    Discuss this download here.
Sign In or Register to comment.