444,190 Members | 1,412 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

# Date difference in C#

 P: n/a Hi, What is the synatx in C# for calculating date difference between 2 dates in terms of no. of days? Thanks, Ben Nov 18 '05 #1
7 Replies

 P: n/a Check out the DateDiff Function http://msdn.microsoft.com/library/de...ctdatediff.asp "Ben" wrote in message news:D0**********************************@microsof t.com... Hi, What is the synatx in C# for calculating date difference between 2 dates in terms of no. of days? Thanks, Ben Nov 18 '05 #2

 P: n/a Why would someone use this for C#? Why not use the Compare method of the DateTime structure? -- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA ************************************************** ******************** Think Outside the Box! ************************************************** ******************** "Michael" wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl... Check out the DateDiff Function http://msdn.microsoft.com/library/de...ctdatediff.asp "Ben" wrote in message news:D0**********************************@microsof t.com... Hi, What is the synatx in C# for calculating date difference between 2 dates in terms of no. of days? Thanks, Ben Nov 18 '05 #3

 P: n/a Better yet, instead of using a VB function and since you're using C# try this: DateTime dt1 = ; DateTime dt2 = ; TimeSpan ts = dt1 - dt2; int days = ts.Days; HTH Brian W "Ben" wrote in message news:D0**********************************@microsof t.com... Hi, What is the synatx in C# for calculating date difference between 2 dates in terms of no. of days? Thanks, Ben Nov 18 '05 #4

 P: n/a Look up "DateTime.Subtract Method". You subtract one from another and get a time span object: TimeSpan ts = date1.Subtract(date2); // both are DateTime NOTE: The suggestion of Compare() in answer to DateDiff (another answer post) was a bit tongue in cheek. ;-> -- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA ************************************************** ******************** Think Outside the Box! ************************************************** ******************** "Ben" wrote in message news:D0**********************************@microsof t.com... Hi, What is the synatx in C# for calculating date difference between 2 dates in terms of no. of days? Thanks, Ben Nov 18 '05 #5

 P: n/a Thanks all. Nov 18 '05 #6

 P: n/a I stand corrected with a big "Whoops!" --a vb.net programmer who thought they had those same things over in the C# world. "Cowboy (Gregory A. Beamer)" wrote in message news:ud**************@TK2MSFTNGP10.phx.gbl... Why would someone use this for C#? Why not use the Compare method of the DateTime structure? -- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA ************************************************** ******************** Think Outside the Box! ************************************************** ******************** "Michael" wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl... Check out the DateDiff Function http://msdn.microsoft.com/library/de...ctdatediff.asp "Ben" wrote in message news:D0**********************************@microsof t.com... Hi, What is the synatx in C# for calculating date difference between 2 dates in terms of no. of days? Thanks, Ben Nov 18 '05 #7

 P: n/a DateTime dt1 = new DateTime(....); DateTime dt2 = new DateTime(...); TimeSpan ts = dt1 - dt2; or use TimeSpan = DateTime.Now - dt1; or whatever Nov 18 '05 #8

### This discussion thread is closed

Replies have been disabled for this discussion.