Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 question
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Freeman II
Junior Member

232 Posts

Posted - 04 July 2001 :  16:01:49  Show Profile
how do you convert a date like this

7/4/2001

to

20010704

which function should i use and how to use it?

thanks



Edited by - freeman II on 04 July 2001 20:44:18

Freeman II
Junior Member

232 Posts

Posted - 04 July 2001 :  20:45:01  Show Profile
i tried cdate() but it didn't work

Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 04 July 2001 :  22:50:55  Show Profile
You can use the datepart function in VBScript to return each component of the date.

Example: nMonth = Datepart("m", #7/4/2001#)

To get other parts of the date, change the "m" to "d" for days, "yyyy" for year.

You'll probably need to make a function to add the leading zero to single-digit months or days.

======
Doug G
======
Go to Top of Page

Freeman II
Junior Member

232 Posts

Posted - 05 July 2001 :  11:17:35  Show Profile
thanks Doug G

Go to Top of Page

aspdesigner
Junior Member

165 Posts

Posted - 05 July 2001 :  16:26:44  Show Profile
VBScript also provides specific functions (Year, Month, Day) to get the information you need to build your new date format. Following is a one-line function that will do the whole thing!


<%
function MyDate(TheDate)
MyDate = CStr(Year(TheDate)) & Right("0" & CStr(Month(TheDate)),2) & Right("0" & CStr(Day(TheDate)),2)
end function
%>


To use it, just pass it the Date you want converted. Example -


New Date Format for today is: <%=MyDate(Now)%>


That's it!


Go to Top of Page

Freeman II
Junior Member

232 Posts

Posted - 05 July 2001 :  22:28:38  Show Profile
thanks aspdesigner

Go to Top of Page

MorningZ
Junior Member

USA
169 Posts

Posted - 05 July 2001 :  22:42:06  Show Profile  Visit MorningZ's Homepage  Send MorningZ an AOL message
and here is what like every ASP message board in existance uses

put on your secret decoder ring )


function doublenum(fNum)
if fNum > 9 then
doublenum = fNum
else
doublenum = "0" & fNum
end if
end function

function StrToDate(strDateTime)
if ChkDateFormat(strDateTime) then
StrToDate = cdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "")
end if
end function

function DateToStr(dtDateTime)
DateToStr = year(dtDateTime) & doublenum(Month(dtdateTime)) & doublenum(Day(dtdateTime)) & doublenum(Hour(dtdateTime)) & doublenum(Minute(dtdateTime)) & doublenum(Second(dtdateTime)) & ""
end function

function ChkDateFormat(strDateTime)
ChkDateFormat = isdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "")
end function


easy as

strDate = DateToStr( Now() ) to "encode" it

formattedDate = StrToDate( strDate ) to "decode" it


Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.26 seconds. Powered By: Snitz Forums 2000 Version 3.4.07