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:

YOOOBB

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)
next

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

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

0 Comments

Submit a Comment

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

You May Also Like…

E-Commerce Learnings

I have a client who had two Wordpress Woocommerce Stores hosted for $20 each a month on cPanel Servers On inspecting...