Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to format a date yyddd

Status
Not open for further replies.

RockJona

Programmer
Nov 14, 2008
7
AR
Does anyone knows how Can I transform a date in format ddmmyyyy to yyddd¿?.
yy is the current year, for example 09.
ddd is the day number in the current year for example 001 for January 1st.

thx!
 
Easy enough to do...

You need to use DateDiff to figure out the number of days since Jan 1.

Code:
Today = Date()
StartOfYear = "1/1/" & Year(Date)
DayOfYear = Right("00" & DateDiff("d", StartOfYear,Today),3)
ShortYear = Right(Year(Date),2)
WScript.Echo ShortYear & DayOfYear[/year]

I hope you find this post helpful.  

Regards,

Mark

Check out my scripting solutions at [URL unfurl="true"]http://www.thespidersparlor.com/vbscript[/URL]

Work SMARTER not HARDER.  The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier!  Save time, get more work done, get the Admin Script Pack.
 
Mark, a simpler way:
Code:
WScript.Echo Mid(1000*Year(Date)+DatePart("y",Date),3)
 
An interesting solution PHV. Oddly enough we get different results.

My code produces 09116 while your code gives 09117.

I was worried about being a day off when I initially did my code, so I tested with a start date of 2 days ago and I got a two day difference. So I think it would be necessary to subtract a day from your results. But I guess that depends on if you want to count a partial day as a full day.

In my mind if the start day is Saturday and today is anytime on Monday, then my expectation is a return of two days. So I would propose a modification to your code as follows:
Code:
WScript.Echo Mid(1000*Year(Date)+(DatePart("y",Date)-1),3)

I love the idea of multiplying the year by 1000, that is just a brilliant idea instead of concatination.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I think the OP want somethink like a julian date and thus my code should be correct.
 
After further thought I think you are correct PHV.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hi folks,

It's be nice if people stopped calling ordinal date representations 'julian dates' - they're not. See:
The Julian date (JD) is the interval of time in days and fractions of a day, since January 1, 4713 BC Greenwich noon, Julian proleptic calendar.
Under ISO 8601, even ordinal date representations should include the century.

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top