Ahmed’s Dev-Shop

Understand DateTime, avoid Format-Hell

Posted in .Net, Engineering, programming, software by Ahmed Siddiqui on April 15, 2009

One of the most common mistakes programmers do is to treat the DateTime as string, or in another words always assuming a specific date format.

How DateTime Works
In strong typed languages like Java and .Net, DateTime contains the
date and time value as a consolidated numeric value without any format specification.
The culture aware ToString() method of DateTime converts the time value
according to the culture/format specifications of the system and configuration.

How to use?
Always use DateTime type for date and time values especially when savin/retriving DateTime values from/to Database.
Always use command parameters with proper types for passing values from application to database.

What to avoid?
Using string to contain DateTime values can become a disaster especially in large application.
You may find yourself trapped in a Format-Hell if you are assuming any particular format in calculation or representation
Never pass Datetime values as string across platforms or contexts for instance application-to-database

Advertisements

One Response

Subscribe to comments with RSS.

  1. Ralph Lauren Barato Espa& said, on March 18, 2014 at 9:08 am

    Its like you read my thoughts! You seem to know so much approximately
    this, such as you wrote the e book in it or something.
    I believe that you can do with some p.c.
    to drive the message house a bit, however instead of that,
    this is fantastic blog. An excellent read.
    I will certainly be back.


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: