theinarasu theinarasu - 1 year ago 172
ASP.NET (C#) Question

different between date format when get current date only using datetime c#

if my computer datetime format as yy/mm/dd or mm/dd/yyyy or regardless formation

Datetime date1 = ... /// assume date1 is date1 < date2 and date1 < date3
DateTime date2 = DateTime.Parse(DateTime.Now.ToString("dd-MM-yyyy")) ;
DateTime date3 = DateTime.Now.Date;

DateTime.Compare(date1 ,date2); and DateTime.Compare(date1 ,date3);

what would the result ? is it for
return 1 when compare
is equal as

Bob Bob
Answer Source

Not sure why are you doing DateTime.Parse(DateTime.Now.ToString("dd-MM-yyyy"));..?

To answer your question, both date2 and date3 will become different depending on your computer (or the device that is running this code) localization.

So if date1 is always earlier you can do TimeSpan diff = date3 - date1; which will give you TimeSpan object. Then you can diff.Days to get the number of days difference.

And yes date3 will only have date in there. The time will be set to 12:00 midnight. See here.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download