Variables and Time... how to make variables recogn

# Thread: Variables and Time... how to make variables recogn

1. Mike M. Guest

## Variables and Time... how to make variables recogn

Hey guys,<BR>Well I have a variable that is received from a form this variable will be in the shape of time eg. 4:21 .<BR>How can I take this variable and make the computer recognize it as time.<BR>I tried this but it generated an error:<BR>t1 = "9:31"<BR>time1 = #t1# &#039;where t1 is a variable containing time<BR><BR>So I want to make a variable in the structure of time actually recognized by the script as time.<BR><BR>Do you understand?<BR>Thanks in advance<BR>Mike M

2. Freddie Spencer Guest

## RE: Variables and Time... how to make variables re

Maybe use CDate() function ? Eg<BR><BR>CDate(t1)

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

## Wasnt it CNN and Time?

&#062;time1 = #t1# <BR>you cant do this. <BR><BR>What are you trying to do. Give us the big picture and we can try and help you.<BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
1,285

## RE: Variables and Time... how to make variables re

try...<BR><BR>t1 = "9:31"<BR>time1 = CDate(t1)<BR><BR>see if that works<BR><BR>you may need to us FormatDateTime() also to get it to look like you want

5. Mike M. Guest

## RE: Wasnt it CNN and Time?

Well the big picture is this. I have a script for a weather station where they enter the time the sun comes up and goes down. I am supposed to display this and the total time the sun is up. I have managed to code the script for figuring out the total time (harder than it sounds) but now the variables arent assigned like in my test script. They are generated from a form where the user type in sunup = 8:40, sundown = 9:20 and from that I have to put these figure into variables that the asp script can process as time since I add 12 hrs to the sundown because its at nigh and then make the difference.<BR>Here is the code to figure out the difference in time now I need the way to make asp know that the variable is time.<BR>N E way here is the script if it helps:<BR><BR><BR>time1 = Request.Form("txtsunup1") &#039;I need to let asp make this var as time<BR>time2 = Request.Form("txtsunset1") &#039;same as above<BR>time2n = time2 + #12:00#<BR><BR>&#039;process difference<BR>nummindiff= Cint(DateDiff("n", time1, time2n))<BR>numhrsdiff_mod= nummindiff MOD 60<BR>numhrsdiff = DateDiff("h", time1, time2n)<BR><BR>if numhrsdiff &#060;&#062; Cint(nummindiff/60) Then<BR> nummindiff = 60 - nummindiff<BR>End if<BR><BR><BR>if numhrsdiff_mod &#060; 10 Then<BR> numhrsdiff_mod = 0 & numhrsdiff_mod <BR>End if<BR><BR><BR>if DatePart("n", time1) &#060;= DatePart("n", time2n) Then<BR> Response.write "difference is " & numhrsdiff & ":" & numhrsdiff_mod <BR>Else<BR> Response.write "difference is " & numhrsdiff -1 & ":" & numhrsdiff_mod <BR>End if<BR><BR><BR>Thanks in advance<BR>Mike M.

6. Mike M. Guest

## It worked thanks alot

. CDate works like a sharm thanks<BR>hadn&#039;t thought of that one<BR><BR>Mike M

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

## In short you wanna add time right?

to add dates or time you HAVE to use the dateadd function<BR><BR>

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

## Maybe a little clearer

To add 12 hours to the time you use <BR><BR>dateadd("h", 12, YourVariable)<BR><BR>you might have to do a cdate to your variable bofore you do this function. Not sure though try it.<BR><BR>basically<BR><BR>time2n = dateadd("h", 12, time2)<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
•