Handle DateTime – Use DotNet Variable


Hey Friends,

Calculating exact Day, Time, No of Month in a Day, Number of days in a Year, Day of the Week and many more has always been a challenging point while writing code in NAV. Though you can manage to achieve this but anyhow you end up with many lines of code. But just twisting your code a little bit with some DotNet variable will bring you a broad smile in your face with just a single line of codes. For an example have a look into the below screenshot.


Just have a look on the above piece of code. Outcome is exactly the same what you are thinking. And here is the output


Below is the description of the DotNet Variable used for the above case. I will recommend each and everyone to have a look on this and explore as it consists of a lot of Methods which can be of great help to you in your daily life as a NAV Programmer.

DotNetDateTime – DotNet – System.DateTime.’mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089′

2 comments on “Handle DateTime – Use DotNet Variable

  1. Pingback: Handle DateTime – Use DotNet Variable - Microsoft Dynamics NAV Community

  2. Hi there,

    nice tip, sounds like keeping up with the times 😉 Anyway. Everybody who tried to use DateTime in a global operation knows this is a PITA. The DateTime value is stored in the database as UTC (based on the client’s or server’s timezone) and will be fetched in local time of the context (client, server). This sounds like a really good idea, but it’s a major PITA in practice. If it would always store and retrieve UTC, it would be fine. But you simply can’t rely on this. This is when you store time in different formats, like a base UTC date with an offset counter in milliseconds or something like that. There’s a reason it is handled this way.

    with best regards


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s