Solved

# Convert Date() to YYYYMMDD

Posted on 2004-09-18
2,547 Views
Wondering what the easiest way to convert the standard asp date formats (9/18/2004) to YYYYMMDD format.  I need to query a btrieve database that uses that format.  I coulnd't find an asp function looking online, and for now I have split the date string and put it back together, this just seems like a lot of code for a simple conversion.
0
Question by:probelaw
• 4
• 3
• 2
• +3

LVL 63

Accepted Solution

Zvonko earned 50 total points
ID: 12093326
My proposal is a two-lines Function:

<%

Function sortDate(pDate)
End Function

Response.Write sortDate("9/18/2004") & "<br>"
Response.Write sortDate(Now()) & "<br>"

%>
0

LVL 2

Expert Comment

ID: 12094075
Zvonko's solution is perfect, this is just another way:

function getEurotime()

timetoday = CStr(FormatDateTime(Now() + 14, 2))
todayinUS = Split(timetoday, "/")
getEurotime = todayinUS(1) + "/" + todayinUS(0) + "/" + todayinUS(2)

end function

This method takes more memory for sure, may be faster though.  Like memory or speed mater at that micro level.

BTW Zvonko are you a Croat?

-Coolhand2120
0

LVL 2

Expert Comment

ID: 12094279
Ooops Just noticed my function there set the time today + 14 days.  I used this script in an application where that was done.

This line:

timetoday = CStr(FormatDateTime(Now() + 14, 2))

timetoday = CStr(FormatDateTime(Now(), 2))

-Coolhand2120
0

LVL 63

Expert Comment

ID: 12094840
I am Mecedonian. But my first name is Crotian ;-)
0

LVL 1

Expert Comment

ID: 12095145
here my simplest code :D one line code

<%
Function EuroDate(strDate)
EuroDate = Format(CDate(strDate),"YYYY/MM/DD")
End Function
%>
0

LVL 63

Expert Comment

ID: 12095227
And what IIS version does your Format() method work?
0

LVL 2

Expert Comment

ID: 12096558
I think thats a VB function.  You can use VB functions in ASP by creating activeX DLLs, but that seems a bit extreme.  I'm not sure ASP supports the VB format function, I'm quite possibly wrong though.

-Coolhand2120
0

LVL 10

Expert Comment

ID: 12097911
I use a function found at http://www.adopenstatic.com/resources/code/formatdate.asp

It may be a bit much for what you want but it allows for all sorts of date and time formatting.  You may end up using it for a multitude of other things you never bothered with because they were too much hassle.
0

LVL 23

Expert Comment

ID: 12104587
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21067836.htm

The above is a question i asked along the lines of yours,

"
Date - a reserved word for Access? Try enclosing Date in square brackets.

SQL = "UPDATE GameDates set [Date]='" & year(d) & "/" & month(d) & "/" & day(d) & "' where DateID = " & i
"
check out the question for full details
0

LVL 23

Expert Comment

ID: 12104597
in your case just re-arrange the statement so that yyyy is first etc
0

LVL 10

Expert Comment

ID: 12106295
Also remember to set your locale so that when seperating months and days it does them in the right order.  http://www.devguru.com/Technologies/vbscript/quickref/LCIDchart.html
0

Author Comment

ID: 12125976
Zvonko's two line function seems like the easiest thing to use for what i need to accomplish.  I can just use it as an include in the pages I need it.  Thanks!
0

LVL 63

Expert Comment

ID: 12127854
Thanks for points and for the feedback.
0

## Featured Post

### Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is tâ€¦
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/â€¦
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods youÂ´d like to investigate in more detail.  The methods are covered in more detail in oâ€¦
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidtâ€¦