Format date DD/MM/YYYY

Hi,
I'm getting a date from a table, and then I want to save it to another table, but I want to save the date in the format dd/mm/yyyy... how do I do that? I don't want to get any 5/5/2004... I want to get 05/05/2004. Thanks for your help

here's my code :

var DateTemp = new Date()
DateTemp = ""+rsGetBGPData("effective_Date")
strFillBgar += "FromDate = '" + DateTemp + "', "  //I build all my SQL statement in the strFillBgar variable then I execute it at the end
LVL 5
DesertWarriorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

masirofCommented:
First split into day month year
and check by LEN if its 2 digits or not, like
if Len(varDAY) = 1 Then varDAY = "0" & varDAY

and join them together :D
0
peh803Commented:
var DateTemp = new Date()

This looks like javascript; if you want to use vbscript, do it like this (this is just masirof's idea, spelled out a bit further)

<%
Dim sMyDate   ' m/d/yyyy format
Dim sNewDate  ' mm/dd/yyyy format
Dim sDay
Dim sMonth
sMyDate = "4/1/2000"
sDay = day(sMyDate)
sMonth = month(sMyDate)

if len(sDay)=1 then
  sDay = "0"&sDay
end if

if len(sMonth)=1 then
  sMonth = "0"&sMonth
end if

sNewDate = sMonth & "/" & sDay & "/" & year(sMyDate)
response.write "Day before conversion: "&sMyDate
response.write "Day after conversion: "&sNewDate

%>  

Hope this helps!
peh803
0
raj3060Commented:
Refer the link:
http://www.psacake.com/web/fr.asp
-Raj
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

peh803Commented:
raj3060 -- good post; does exactly what mine does, except in a function.  Useful for sure!

peh803
0
aprestoCommented:
this is a very lame suggestion compared to other but would it work if you put this neat the top of your code:

<% session.lcid = 2057 %>

but that might just display them in british date format
0
kmorris1186Commented:
Here is a DLL that i use that will allow you to format dates and times just like you would in VB..

http://www.4guysfromrolla.com/demos/FormatDemo.asp

It is freeware, but is an active X dll.  If your trying to stay away from that, this will not help.
0
DesertWarriorAuthor Commented:
Sorry guys, I forgot to mention : I work only with javascript...

peh803, can you translate that code into javascript?
0
peh803Commented:
There seems to be a good js formatDate function here:
http://www.mattkruse.com/javascript/date/compact_source.html
0
peh803Commented:
Or, how about this?

function getDisplayDate(passedDate) {
    // MM/DD/YYYY

    theDate = new Date(passedDate);

    // split into day, month, year
    iDay = theDate.getDate();
    iMonth = theDate.getMonth();
    iYear = theDate.getFullYear();

    sDisplayDate = iMonth + "/" + iDay + "/" + sYear;

    return sDisplayDate;
}

// example use
now = new Date();
document.writeln("Today's Date is: " + getDisplayDate(now));
0
gita_boradCommented:
You can try SQL convert function with style to do this easily

E.g. select convert(varchar, convert(datetime,('5/5/2004')), 103)
will give you "05/05/2004"

So, use
strFillBgar += "FromDate = convert(varchar, convert(datetime,('" + DateTemp + "')), 103)"
0
kmorris1186Commented:
That is, only if they are using MSSQL...

I use MySQL and dont have that luxary..
0
Brad Dobyns, CSMScrumMasterCommented:
Not sure that that will include the "0" in front of the numbers like he wants. You have to include a conditional:

if (iDay< 10) iDay = ("0" + iDay + ", ");
if (iMonth< 10) IMonth = ("0" + iMonth + ", ");

Try this (this is what I use):

var calendar = new Date();
var iMonth = calendar.getMonth();
var iDate = calendar.getDate();
var iYear = calendar.getYear();
if (iYear < 1000)
      iYear += 1900;
var cent = parseInt(iYear/100);
var g = iYear % 19;
var k = parseInt((cent - 17)/25);
var i = (cent - parseInt(cent/4) - parseInt((cent - k)/3) + 19 * g + 15) % 30;
      i -= parseInt(i/28) * (1 - parseInt(i/28) * parseInt(29/(i+1)) * parseInt((21-g)/11));
var j = (IYear + parseInt(iYear/4) + i + 2 - cent + parseInt(cent/4)) % 7;
var l = i - j;
var emonth = 3 + parseInt((l + 40)/44);
var edate = l + 28 - 31 * parseInt((emonth/4));
      emonth--;
if (iMonth< 10)
     iMonth = ("0" + iMonth + ", "); // if you want leading zero on month
if (iDate< 10)
    iDate = ("0" + iDate + "/"); // if you want leading zero on date
DateTemp = IMonth + IDate + IYear;

This takes into account leap year and February.

Hope that helps,
Brad
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.