Solved

Convert Date() to YYYYMMDD

Posted on 2004-09-18
13
2,553 Views
Last Modified: 2012-08-14
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
Comment
Question by:probelaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 63

Accepted Solution

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

<%

Function sortDate(pDate)
    aDate = CDate(pDate)
    sortDate = Year(aDate)&Right("0"&Month(aDate),2)&Right("0"&Day(aDate),2)
End Function


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


%>
0
 
LVL 2

Expert Comment

by:Coolhand2120
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

by:Coolhand2120
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))


Should read:

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


-Coolhand2120
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Expert Comment

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

Expert Comment

by:InVisal
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

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

Expert Comment

by:Coolhand2120
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

by:dij8
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

by:apresto
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,

this is the accepted answer:

"
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

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

Expert Comment

by:dij8
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

by:probelaw
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

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Classic ASP - problem with MS SQL Select Query? 10 61
SQL to update characters in table column 6 160
Weighted Randomizing 6 33
Making Table Thru ASP Response.write 5 19
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question