Converting a String to Integer Problem: This has t

# Thread: Converting a String to Integer Problem: This has t

1. Senior Member
Join Date
Dec 1969
Posts
661

## Converting a String to Integer Problem: This has t

Hi,<BR><BR>All I want to do is grab the hour and convert it to a integer.<BR><BR>Here is my test code. I am using Cint to convert.<BR><BR>thanks in advance:<BR>&#060;%<BR>zeTime = FormatDateTime(Now, 4)<BR>zeHour = Cint(Left(zeTime,2))<BR>response.write zeHour & "<BR><BR>"<BR>%&#062;<BR><BR>If it is 10 in the morning it will write 10 which should be an integer, but it is not. It seems to be a string because I cannot do any mathematical comparisons on this value.<BR><BR>pelican<BR><BR> <BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
3,921

## For Math

you&#039;ll need to continually use the CInt() function around your<BR>variables. All ASP variables are considered Variants.<BR><BR> nVal = Cint(nVal1) + Cint(nVal2)

3. Senior Member
Join Date
Dec 1969
Posts
661

## RE: For Math

Thanks.......

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

## *MUCH* Better Way!!!

&#060;% <BR>zeTime = Now()<BR>zeHour = Hour( zeTime )<BR>%&#062;<BR><BR>Presto! Do *NOT* use FormatDateTime! BIG MISTAKE! That converts the already-in-a-Date-variable value to a string. Then you have to tear apart the string. Then you have to convert that back to a number if you want to use it as a number.<BR><BR>Learn to manipulate Date values *as* Date values, instead of as strings!<BR><BR>Look at the functions: DateAdd, DateDiff, Hour, Minute, Second, Year, Month, Day, DatePart ... and I&#039;ve probably forgotten a couple. But that&#039;s what the VBScript Reference manual is for.<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
•