Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Convert Date to DateTime

(0) ShareShare
ReportReport
Posted on by 985

Good day House. Please I am facing a challenge now. I have to assign a "Date" Value to a "DateTime" variable. How do I convert the "Date" to a "DateTime"?

Thanks for your help.

*This post is locked for comments

  • Suggested answer
    Nadeem Altaf Profile Picture
    10 on at
    RE: Convert Date to DateTime

    DateTime := CREATEDATETIME(Date, Time)

  • 4BzSoftware Profile Picture
    6,073 on at
    RE: Convert Date to DateTime

    Hi Toffsam,

    I replied your email and also added your Skype.

    I'm looking for a Remote or Part-Time Position. I have 6 hours/day available and would like to provide it to any company looking for NAV experience person.

  • Toffsam Profile Picture
    985 on at
    RE: Convert Date to DateTime

    Hi Khoa,

    I sent you an email  on this Remote/Part-Time Position.

    Thanks.

  • 4BzSoftware Profile Picture
    6,073 on at
    RE: Convert Date to DateTime

    You are welcome, have a nice day!

  • Toffsam Profile Picture
    985 on at
    RE: Convert Date to DateTime

    Thanks Khoa. It works.

  • Verified answer
    4BzSoftware Profile Picture
    6,073 on at
    RE: Convert Date to DateTime

    Hi Toffsam,

    Change a little bit your code:

    varEndDate := CREATEDATETIME(CALCDATE('CM', EndDate), 0T);

    SETFILTER(LastDayMonth, '<=%1', varEndDate);

  • 4BzSoftware Profile Picture
    6,073 on at
    RE: Convert Date to DateTime

    Hi Toffsam,

    Totally agree with Stefano:

    "YourDateTime := CREATEDATETIME(YourDate,0T);"

    Another way is:

    IF EVALUATE(YourDateTime, FORMAT(YourDate)) THEN;

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Convert Date to DateTime

    I think that the problem is in the CALCDATE function. The second parameter must be a Date value.

  • Toffsam Profile Picture
    985 on at
    RE: Convert Date to DateTime

    Hi Demiliani,

    thanks for your reply. Yes I tried that before but still could not achieve my aim . What I really want to achieve is setfilter on a DateTime field in a table, now the value to setfilter with is a Date value and am getting error: Conversion is not possible Date:= DateTime.

    This is my code:

    varEndDate := CREATEDATETIME(EndDate,0T);

    SETFILTER(LastDayMonth,'<=%1',CALCDATE('CM', varEndDate));

    Note: "LastDayMonth" is  a DateTime field from the record(Table) which holds last day of

              month for a date.

              "EndDate"  is a Date value coming from Request page

               "varEndDate"  is the DateTime variable i am assigning my converted date value so I    

               can setfilter on my record.

    I get the error on the SETFILTER(LastDayMonth,'<=%1',CALCDATE('CM', varEndDate)); lin e that "Conversion is not possible because 1 of the operators contain an invalid type.  Date:= DateTime."

    Please how can I achieve this filter.

    Thanks again.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Convert Date to DateTime

    You can do like this:

    YourDateTime := CREATEDATETIME(YourDate,0T);  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
EH-09052238-0 Profile Picture

EH-09052238-0 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 1

Featured topics

Product updates

Dynamics 365 release plans