Converting a date to an Integer

# Thread: Converting a date to an Integer

1. Junior Member
Join Date
Dec 1969
Posts
4

## Converting a date to an Integer

Need to convert a date to an integer, where the date returned is:<BR><BR>01/07/2003 (I&#039;m in australia)<BR><BR>I need the integer to be 01072003<BR><BR>Is this possible, I cannot change it from 1/7/2003.<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: Converting a date to an Integer

Day(date) & Month(Date) & Year(Date) should do the job, shouldn&#039;t it?? or possibly :<BR><BR>Day(date) & "" & Month(Date) & "" & Year(Date)<BR><BR>to make sure it stringifies. don&#039;t see what the problem is....<BR><BR><BR><BR>j<BR>http://rtfm.atrax.co.uk/

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

## Impossible...because...

NUMBERS never have leading zeroes.<BR><BR>Oh, you can type in a number with a leading zero, but it will *NOT* be remembered as such.<BR><BR>So if you do<BR>&#060;%<BR>dateNumber = 01072003<BR>Response.Write dateNumber<BR>%&#062;<BR>you will see just<BR> 1072003<BR>written back out.<BR><BR>Might I suggest that, if you are going to do something like this, you should always put the YEAR first, then the month, then the day?<BR> 20030701<BR><BR>If you do that, you don&#039;t have a problem with leading zeroes (except for years before 1000 A.D.) and on top of that the numbers will compare correctly: That is 4 December 2003 will come AFTER 7 February 1947, which it won&#039;t with your system.<BR><BR>Your system:<BR> 07021947 ==&#062;&#062; 7021947<BR> 04122003 ==&#062;&#062; 4122003 which is less than 7021947<BR>The ISO system (one name for this):<BR> 19470207<BR> 20031204 which is clearly larger than 19470207<BR><BR><BR>

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

## Ummmm...is it Friday?

Day(date) & Month(Date) & Year(Date) for Thursday:<BR> 3172003<BR>For Friday:<BR> 182003<BR><BR>I think you are missing the leading zeroes, no?<BR><BR>On top of which, you just produced a string, *NOT* a number.<BR><BR>To produce a number:<BR> dayInteger = Day(theDate) * 1000000 + Month(theDate) * 10000 + Year(theDate)<BR><BR>Or, if you use the ISO system, as I recommend:<BR> isoInteger = Year(theDate) * 10000 + Month(theDate) * 100 + Day(theDate)<BR>

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

## And by the by...

...this is *NOT* an ADVANCED question. Next time, ask this kind of question in the standard ASP Q&A forum, please?<BR><BR>(Though I grant you, if Atrax can get the wrong answer to a question, maybe it should be considered at least non-beginner.)<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: Ummmm...is it Friday?

ah, OK. you know I don&#039;t use VBS!

7. Junior Member
Join Date
Dec 1969
Posts
4

## RE: Ummmm...is it Friday?

Yes this did it for me...<BR><BR>To produce a number:<BR>dayInteger = Day(theDate) * 1000000 + Month(theDate) * 10000 + Year(theDate)<BR><BR>Or, if you use the ISO system, as I recommend:<BR>isoInteger = Year(theDate) * 10000 + Month(theDate) * 100 + Day(theDate)<BR><BR><BR>Thanks You., i was missing the leading zeros<BR><BR>Simon

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

## Lousy excuse...

&nbsp;<BR>var dt = new Date(); // or similar<BR>var isoInteger = 10000 * dt.getYear() + 100 * dt.getMonth() + dt.getDate(); <BR><BR>Hmm???<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
•