Tuesday, March 4, 2008

Get Time Part of the DateTime in .net

Imran Younus, a software engineer and a relational algebra expert (believe me!) has an interesting tip for people who wish to get time part of datetime, in .net, for comparison purposes;

dMyDateTime.Ticks - DateTime.Parse(dMyDateTime.ToShortDateString).Ticks

This will give least value for 12:00 AM and max value for 11:59:59 PM

2 comments:

Unknown said...

Couldn't one just use dMyDateTime.TimeOfDay.Ticks to achieve the same thing?

Unknown said...

Yes you are right but the way I'm doing we can use the portion being subtracted as displacement and adjust the starting time instead of 12:00 AM as least