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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Date 1

Status
Not open for further replies.

djmc

Programmer
Jun 12, 2002
179
0
0
CA
How do i format a date from 01-01-2003 to 01-01-03
It is retrieved form a table field in an access database using short date format
Thanks.
 
faq333-3194

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
djmc,

You can try the below... Asumming that you have a predefined format like the one that you had posted...

<%
origdate = &quot;01-01-2003&quot;
arrayorigdate = Split(origdate, &quot;-&quot;)
arrayorigdate(2) = Right(arrayorigdate(2) ,2)
newdate = join(arrayorigdate,&quot;-&quot;)
response.write newdate
%>

HTH..

Happy programming...
 
Definitely check the FAQ, as it points out a much simpler way of doing it using a built-in VBScript function.
 
the faq shows methods of breaking a date up and reassembling it, search google for &quot;FormatDate Function&quot;
it's built in to VB 5/6 and has ALOT of date display and modification functionalities even down to spitting out the text based representation of a date (Monday, June 15, 1999) etc ..
 
DreXor
Please read the FAQ again. I've included every possibility including the FormatDate Function
<src FAQ>
second method is the FormatDateTime function
many VBers will know this function well, but overlooked many times in vbscript/ASP
example:
Dim curDate
curDate = Now()
Response.Write &quot;vbGeneralDate - &quot; & FormatDateTime(curDate, vbGeneralDate) & &quot;<BR>&quot;
Response.Write &quot;vbLongDate - &quot; & FormatDateTime(curDate, vbLongDate) & &quot;<BR>&quot;
Response.Write &quot;vbShortDate - &quot; & FormatDateTime(curDate, vbShortDate) & &quot;<BR>&quot;
Response.Write &quot;vbLongTime - &quot; & FormatDateTime(curDate, vbLongTime) & &quot;<BR>&quot;
Response.Write &quot;vbShortTime - &quot; & FormatDateTime(curDate, vbShortTime) & &quot;<BR>&quot;

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
well, alright I'll make it clear on the FormatDate!!! function
[lol]

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
vbGeneralDate - 6/27/2003 2:57:03 PM
vbLongDate - Friday, June 27, 2003
vbShortDate - 6/27/2003
vbLongTime - 2:57:03 PM
vbShortTime - 14:57

This is the output that I got.
Apparently vbShortDate returns 6/27/2003 and not 6/27/03 (which is what i want)
 
.......
.......
then you need to format your date with a bit of intervention
eg: right() function and rebuild the date
MyYear = right(Year(Date()),2)

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
as gladxml already stated I see!

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top