How to trim the datetime in c#?

by Victor 23. August 2009 04:14

Last week I need to write something to compare two datetime at the second level. So I have to trim the datetime part after second. There is the function I used to trim the datetime. 

 

public static DateTime TrimDate(DateTime date, long ticks)
{
    return new DateTime(date.Ticks - date.Ticks % ticks);
}

Examples about how to use the function

DateTime datNewDate = TrimDate(oldDate, TimeSpan.TicksPerSecond); 

Easy! 

 

Tags:

Programming

Comments (1) -

Link buildin guy
Link buildin guy United States
4/5/2010 4:03:40 PM #

I just noticed that your blog is on a BlogEngine platform. I like the look and feel of this platform. I might even switch my blog to a BE blog!

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

Month List