Formating a date from a number

# Thread: Formating a date from a number

1. Senior Member
Join Date
Dec 1969
Posts
170

## Formating a date from a number

Could somebody please help me imrove the way I convert the number 20030716 so I can display it nicely in a FormatDateTime function?<BR><BR>This is how I am doing it currently. Can I imporve on this?<BR><BR>dtYear = Left("20030716", 4)<BR>dtMonth = Right(Left("20030716", 6), 2)<BR>dtDay = Right("20030716", 2)<BR><BR>dtDate = dtMonth & "/" & dtDay & "/" & dtYear<BR><BR>dtDisplayDate = FormatDateTime(dtDate , 2)<BR><BR>Thanks <BR><BR>Renee<BR><BR>Ps. The number will come from a database, so I wont be duplicating it in each conversion :)

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

## Looks okay to me...

Although replacing<BR> dtDate = dtMonth & "/" & dtDay & "/" & dtYear<BR>with<BR> dtDate = DateSerial( dtYear, dtMonth, dtDay )<BR>is perhaps more aesthetic.<BR><BR>And you could very slight simplify the month:<BR> dtMonth = Mid( "20030716", 5, 2 )<BR><BR>BUT...<BR><BR>But maybe it would be better to convert this to a date in SQL???<BR><BR>What kind of database is this? Why isn&#039;t that a datetime field in the DB instead of a VARCHAR (or CHAR?)???<BR><BR>

3. Junior Member
Join Date
Dec 1969
Posts
5

## RE: Formating a date from a number

it depends on the use of the date. what will the date be used for?

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

## What???

He is *CLEARLY* doing <BR> FormatDateTime( dtDate, 2 )<BR>which clearly says *exactly* what he is using the date for.<BR><BR>I don&#039;t understand your comment, at all.<BR>

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

## Actually...

...if that is *truly* a number, then using string functions to take it apart is silly.<BR><BR>Much better:<BR><BR>&#060;%<BR>dtDate = RS("someDateThatIsStoredAsNumber")<BR><BR>dtDate = DateSerial( dtDate10000, (dtDate100) MOD 100, dtDate MOD 100 )<BR><BR>dtDisplayDate = FormatDateTime( dtDate, 2 )<BR>%&#062;<BR><BR>Yes, those are backslashes there. That&#039;s VBScripts "integer divide" operator.<BR><BR>So:<BR> 20030716 10000 ==&#062;&#062; 2003<BR> (20030716 100) MOD 100 ==&#062;&#062; 200307 MOD 100 ==&#062;&#062; 7<BR> 20030716 MOD 100 ==&#062;&#062; 16<BR><BR>See?<BR><BR><BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
170

## Thanks Bill... But I'm not a HE :)

Renee :)

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

## You're sure now?

I presume you&#039;ve checked recently?<BR><BR>&#060;grin/&#062;<BR><BR>Actually, when I made that answer I didn&#039;t have your mail or name in front of me. Not that I would have been 100% sure, in any case: Maybe you were "Rene E.", for example.<BR><BR>But hey! You didn&#039;t answer the question: What DB is this coming from? It isn&#039;t possibly MySQL is it??? If so, you can tell it to produce a DATETIME value from the number and then you won&#039;t need to do *any* conversion.<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
•