# days calculation [Answered]RSS

## 5 replies

Last post Jan 27, 2014 05:35 AM by AidyF

• sheetha

Member

5 Points

29 Posts

### days calculation

Jan 27, 2014 05:03 AM|sheetha|LINK

hi!

how to calculate duratin between two dates inmvc pls help me

• AidyF

All-Star

37441 Points

9077 Posts

### Re: days calculation

Jan 27, 2014 05:09 AM|AidyF|LINK

```DateTime dtA;
DateTime dtB;

// populate dtA and dtB from somewhere

TimeSpan ts = dtB - dtA;

// ts now has various properties to give you the time difference in anything from milliseconds to years```

I'm afraid I no longer use this forum due to the new point allocation system.
• ignatandrei

All-Star

119952 Points

27912 Posts

Moderator

MVP

### Re: days calculation

Jan 27, 2014 05:18 AM|ignatandrei|LINK

On the server: with datetime diff

On the client: transform into datetime the values and make the diff in javascript.
Please tell which case do you want

• kedarrkulkar...

All-Star

27258 Points

6184 Posts

### Re: days calculation

Jan 27, 2014 05:19 AM|kedarrkulkarni|LINK

like this

```DateTime dt1 = DateTime.ParseExact("27/01/2014", "dd/MM/yyyy", CultureInfo.InvariantCulture);
DateTime dt2 = DateTime.ParseExact("19/01/2014", "dd/MM/yyyy", CultureInfo.InvariantCulture);

int dateDifference = (dt1 - dt2).TotalDays;```

hope this helps...

Cheers!
KK

Please mark as Answer if post helps in resolving your issue
My Site
• sheetha

Member

5 Points

29 Posts

### Re: days calculation

Jan 27, 2014 05:25 AM|sheetha|LINK

hi i want the client side

• AidyF

All-Star

37441 Points

9077 Posts

### Re: days calculation

Jan 27, 2014 05:35 AM|AidyF|LINK

Javascript isn't very well suited to date functions, mainly as you don't know the client's location and date settings.

http://www.htmlgoodies.com/html5/javascript/calculating-the-difference-between-two-dates-in-javascript.html#fbid=Sm1vcuuLC29

I'm afraid I no longer use this forum due to the new point allocation system.