# Thread: Writing a code to countdown hours and minutes until tomorrow

1. ## Writing a code to countdown hours and minutes until tomorrow

Hey Everyone,

So I'm trying to write a script to countdown the number of hours and minutes until tomorrow. So far, this is what I have:

Code:
```<%
response.write(dateDiff("h",now(),date+1)) & " hours and " & dateDiff("m",Time(),date+1) & " Minutes "
%>```
The code above correctly displays the hours until tomorrow... but it's not displaying the minutes correctly. It's displaying the total minutes until tomorrow. If there at 4 hours left until tomorrow it's saying "4 Hours and 240 minutes."

I need it to display "4 hours and 0 minutes."

The best way I think this can be done is to take the current time in minutes and subtract that from 60. What you have left is the total minutes until the next hour.

So... can someone help me figure our how to take the current time in minutes and subtract that from 60?

2. First point to make is that "m" returns months in datedif. You need to use "n" to return minutes.

I think this will do what you want:
Code:
```<&#37; diff_in_minutes = dateDiff("n",now(),date+1)
response.write(Cstr(diff_in_minutes\60) + " hours and " + Cstr(diff_in_minutes mod 60) + " minutes")
%>```

3. Originally Posted by ReggieB
First point to make is that "m" returns months in datedif. You need to use "n" to return minutes.

I think this will do what you want:
Code:
```<% diff_in_minutes = dateDiff("n",now(),date+1)
response.write(Cstr(diff_in_minutes\60) + " hours and " + Cstr(diff_in_minutes mod 60) + " minutes")
%>```
Thanks Reggie,

I had been playing around with this all day today and I finally got it working . Thank you for the help.

4. Did you spot that:
Code:
`Cstr(diff_in_minutes mod 60)`
returns a fraction of an hour? This bit needs to be:
Code:
`Cstr(60*(diff_in_minutes mod 60))`
I slept on it and realised I'd made a mistake.

#### Posting Permissions

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