How do I convert the Ordinal Date in Progress 9.1D?

Posted by Admin on 12-Apr-2011 13:52

I need to convert a calendar date, MM/DD/YYYY, into the Ordinal Date, YYYYDDD: where DDD is the day of the year (e.g. April 11, 2011 equals the Ordinal Date 2011211).  If it helps anyone reading this, the Ordinal Date is also known as the "Julian Long Day" or the "ISO-8601 Day of Year".  I also need to be able to convert the Ordinal Date back into a calendar date.  How can I do this using Progress 9.1D (character, not GUI)?  Thanks in advance for your help.

All Replies

Posted by Admin on 13-Apr-2011 01:39

It might be a mistake in your post as for April 11, 2011 the day of the year should be 101 not 211... http://www.calendarhome.com/converter/

something like that might work

FUNCTION toOrdinal RETURNS INTEGER (dt AS DATE):

    RETURN YEAR(dt) * 1000 + dt - DATE(1, 1, YEAR(dt)) + 1.

END FUNCTION.

FUNCTION fromOrdinal RETURNS DATE (dt AS INTEGER):

    RETURN DATE(1, 1, INTEGER(TRUNCATE(dt / 1000, 0))) + (dt MODULO 1000) - 1.

END FUNCTION.

Posted by Admin on 13-Apr-2011 08:16

Thank you, Marian!!  These Functions work perfectly for my needs.  You made my day! 

This thread is closed