web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    You can do like this:

    YourDateTime := CREATEDATETIME(YourDate,0T);  

  • Toffsam Profile Picture
    985 on at

    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

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

  • 4BzSoftware Profile Picture
    6,073 on at

    Hi Toffsam,

    Totally agree with Stefano:

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

    Another way is:

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

  • Verified answer
    4BzSoftware Profile Picture
    6,073 on at

    Hi Toffsam,

    Change a little bit your code:

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

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

  • Toffsam Profile Picture
    985 on at

    Thanks Khoa. It works.

  • 4BzSoftware Profile Picture
    6,073 on at

    You are welcome, have a nice day!

  • Toffsam Profile Picture
    985 on at

    Hi Khoa,

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

    Thanks.

  • 4BzSoftware Profile Picture
    6,073 on at

    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.

  • Suggested answer
    Nadeem Altaf Profile Picture
    10 on at

    DateTime := CREATEDATETIME(Date, Time)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans