vbscript date format

45 pts.
Tags:
VBScript
Hi guys been trying to play around with a date format so that it reads ddmmyy instead of ddmmyyyy eg:150110 instead of 15012010 sYesterday = Day(dYesterday) & Month(dYesterday) & Year(dYesterday) Thanks for the help!! :) Rain

Software/Hardware used:
vbscript

Answer Wiki

Thanks. We'll let you know when a new response is added.

You could use the <a href=”http://msdn.microsoft.com/en-us/library/eh8fefz1(VS.85).aspx”>Right Function</a>.

Something like this:

<pre>sYesterday = Day(dYesterday) & Month(dYesterday) & <b>right(</b>Year(dYesterday)<b>,2)</b></pre>

-CarlosDL

———————————

kccrosser:

There is a FormatDateTime function in VBScript that gives the date/time back in a variety of formats. If you use the “short date” format, it returns “mm/dd/yy”.

sYesterday = FormatDateTime(dYesterday, 2)

This will result in sYesterday containing “01/27/10″ (as of 1/28/2010).

Then, use the Replace function to strip the “/” characters:

sYesterday = Replace(sYesterday, “/”, “”)

Or, put them together as:

sYesterday = Replace ( FormatDateTime ( dYesterday, 2 ) , “/”, “”)

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Defector
    CarlosDL & kccrosser.....thanks alot for the help. Really appreciated!! I went with CarlosDL's code as it fits inline with the rest of the script and nests nicely. I will definately keep kkcrosser's as I know I will be able to use that for sure. Can the date be changed around to format dd/mm/yy? PS: you guys make it look to easy....thanks again for helping a newbee :)
    45 pointsBadges:
    report
  • carlosdl
    "Can the date be changed around to format dd/mm/yy?" It would depend on the machine's regional settings. Take a look at this: FormatDateTime Function (MSDN)
    69,510 pointsBadges:
    report
  • Defector
    [...] Defector asks about switching around a VBScript’s date display, and Kccrosser and CarlosDL both provide [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following