Date to Ordinal Days

Written by James McDonald

June 15, 2009

I recently had to create a reasonably meaningful batch number for some GS1 compliant SSCC labels.

I have an Internet Explorer Interface that submits the request to our ERP system.

Due to legacy issues the batch number was restricted to 6 numeric digits. Some colleagues and I ended up coming up with a format of:


Where Y is the right most digit of the current year (2009 = 9)

Where OOO is the zero filled ordinal day of the year (January 1 = 001 , 15 June 2009 = 166)

And BB is a user interface selected 2 digit batch no. (01, 02, 0x – 99)

To get the Ordinal Day of the year was an excercise in Googling. Here is the algorithm I found embedded in someones html page… Sadly I can’t attribute because I can’t seem to Google back to it. So if it’s yours let me know and I will.

Javascript Ordinal Date

VBScript Ordinal Date

myDate = Date
days = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
' now calc date
y = year(myDate)
' array is zero based so make 
' the month the same 0 = jan, 1 = feb etc
m = month(myDate) - 1
d = day(myDate)

' find out if it's a Leap Year
if ( 0 = y mod 4 ) then
        ' add one day to february if it's a leap yr
	days(1) = days(1) + 1
end if

for i = 0 to m - 1
        ' if june you need to add the first 5 months totals 
	myDays = myDays + days(i)

'then add the final months day value
myDays = myDays + d

msgbox "Date : " & date & vbcrlf & "Ordinal Days : " & myDays


Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

Scam call from “Telstra”

Just had a call from a man with a sub-continental accent from caller ID 0734946596 Told me there was problem with my...

PC Build

I recently built myself a PC using the SilverStone SG13 Case. I am planning to use it as a Hot Spare. So any client...