How to calculate number of days between two dates

# Thread: How to calculate number of days between two dates

1. Senior Member
Join Date
Dec 1969
Posts
423

## How to calculate number of days between two dates

Hi,<BR><BR>Can some one tell me a quick way to calculate the number of days between two dates that are stored as asp variables.<BR><BR><BR>Cheers<BR><BR>Mark

2. Senior Member
Join Date
Dec 1969
Posts
11,247

## Duh Datediff <nt>

.

3. jpn
Senior Member
Join Date
Dec 1969
Posts
687

## well mark...

ofcourse its datediff<BR><BR>but you could have framed your sentence in a nicer way, probably a request cos no one here works for you...its an forum where people help each other with their ideas and thoughts.<BR><BR>Hope I am not being rude.

4. Senior Member
Join Date
Dec 1969
Posts
423

## RE: well mark...

Sorry,<BR><BR>Thanks sooo much for the info.<BR><BR>Mark :)

5. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## LOL....

mood off......stuck in traffic today?<BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Double DUH: Just subtract them

Example:<BR><BR>&#060;%<BR>newYearsDay = #1/1/2005#<BR><BR>Response.Write "There are still " & ( newYearsDay - Date() ) & " days in 2004."<BR>%&#062;<BR><BR>Yes, DateDiff is more elegant. And if one or both of your variables have both date *AND* time stored in them, it&#039;s a better thing to use.<BR><BR>But for date-only values, you can subtract to get difference in days. And you can simply add an integer to a date to get another date:<BR><BR>&#060;%<BR>Response.Write "10 days from now is " & (Date() + 10)<BR>%&#062;<BR>

7. Senior Member
Join Date
Dec 1969
Posts
11,247

## Hey he wanted a Quick response

and it was the first thing that popped into my little brain

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## JPN implied same thing...

...but I didn&#039;t see that in his message.<BR><BR>He said<BR> Can some one tell me a quick way ...<BR><BR>I read that to mean he wanted a short and easy answer instead of a long convoluted one. (I suspect that he was envisioning having to do it all by hand...counting days in each month or some such ugly stuff.)<BR><BR>Anyway, obviously DATEDIFF is not a wrong answer. Heck, it&#039;s actually the only right answer if one or both the values include a time component. My "double duh" was just me hassling you for the fun of it. Sorry.<BR><BR>Here&#039;s a fun one to try:<BR><BR>&#060;%= Now() - Date() %&#062;<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: JPN implied same thing...

I&#039;d suspect you get an error right?<BR>hmmm now I&#039;m not sure Time()?<BR><BR><BR>ok I go with Time()

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## No error! Try it!

I really did mean to try it. <BR><BR>More fun:<BR><BR>&#060;%<BR>Response.Write "diff: " & ( Now() - Date() ) & "&#060;P&#062;" <BR>Response.Write "time as double: " & CDbl( Time() )<BR>%&#062;<BR><BR>Quiz for today: Explain the results.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•