Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing dates and times - converting to numbers

Status
Not open for further replies.

avivit

Technical User
Jul 5, 2000
456
IL
How do I convert date and time into a number?
I would like the user to enter a date, and time for a msg to appear in that time, and a date and time that msg to dissapear (i.e. - I want to know from when to when will the msg apear).
Now, I want to compare it to the date and time of the server of course(when asp page is opened).
I thought if I could convert the time/date to a number (like it is in excel), I can compare the values easily.
Otherwise I need to build if conditions. I prefer the clean way if there is one.

I can't just compare dates or just the times, because there's a probelm when the time in the endDATE is smaller than the time in the beginDate.
Foe e.g. - begin date and time: 15:46 21/7/01
end date and time: 14:30 23/7/01

Any suggestions?
 
Or change to seconds... "Cant see wood for tree's...!"
 
Thanks yandso and gsc1ugs.

I used it as follows:
if (DateDiff(&quot;S&quot;,startDateTime,nowDateTime)>=0) AND (DateDiff(&quot;N&quot;,nowDateTime,finishDateTime)>=0) then <<do stuff>>

startDateTime,nowDateTime and finishDateTime are all variables that consist the time and date in the following format e.g.: &quot;12/7/01 13:54&quot;

Now, I have another question: How can I know the server clock settings(Regional Settings Properties)? I noticed it's different than my clock settings(when I use my PWS), and it causes problems, for the format is different.
For e.g.: &quot;7/24/01&quot; in the server is &quot;24/7/01&quot; in my comp. I need to know if &quot;1:54&quot; is not &quot;01:54&quot; etc.

I DO NOT HAVE ACCESS to the server pc, besides access to put pages there. Can I know it's clock settings? Some code to response.write these settings?
Btw - Am I looking for the right settings (Is it the &quot;Regional Settings Properties&quot;(date style and time style) I need to take care of)?

I want to adjust my comp settings to the server's.

Thanks much
 
Hi

I would you stuff like this because it works out the seconds from date specified.

Dim nTimeResult1,nTimeResult2,nTimeResult3
nTimeResult1 = DateDiff(&quot;s&quot;, #24/3/2001#, Now)
nTimeResult2 = DateDiff(&quot;h&quot;, #3/24/2001#, Now)
nTimeResult3 = DateDiff(&quot;d&quot;, #3/24/2001#, Now)

Response.Write &quot;<b>Time in secs - &quot; & nTimeResult1 & &quot;</b><br>&quot;
Response.Write &quot;<b>Time in hours - &quot; & nTimeResult2 & &quot;</b><br>&quot;
Response.Write &quot;<b>Time in days - &quot; & nTimeResult3 & &quot;</b><br>&quot;

and yes regional settings, these are kept ticking on the motherboard.

gsc1ugs gsc1ugs
&quot;Cant see wood for tree's...!&quot;
 
Thanks much.

What is the &quot;#&quot; good for, when u type it before the date? What does it do?

So u r saying that I don't need to know the format itself?
&quot;dd/mm/yy&quot; etc.??? Just compare the dates and time though they have different formats? Because the dateDiff(&quot;s&quot;...) give a number of the seconds? Do I understand it right?
I must say...it makes sense.

Thanksssssss
 
Yep,

yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second

I think the '#' is to specify your own date, not sure though., instead of Now() for instance.
gsc1ugs
&quot;Cant see wood for tree's...!&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top