These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Format a Current Date Field for Julian Date

TerryClawth
Registered: Jul 18 2008
Posts: 6

Using LiveCycle Designer 7.0 on Windows XP, I am creating an interactive static invoicing form and want to use the current date in the Julian Date (numeric) format as part of the automatic numbering system.

Neither the Object Field Display Pattern or the Binding Data Pattern give me a numeric option.

Got any suggestions?

My Product Information:
LiveCycle Designer, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You can use JavaScript to perform the calculation. Using the Date object, get the current date, use the valueOf property to get the number of milliseconds since Jan 1 1970 Midnight, convert that to days, add the number of days from Jan 1 4713 BC (Noon) to Jan 1 1970 (2440587.5), and set the field value to the result.

George
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Or do you mean the Ordinal day of the year:

// define some date time constants
var fSec = 1000;
var fMin = 60 * fSec;
var fHr = 60 * fMin;
var fDay = 24 * fHr;
// get today's date time object
var oNow= new Date();
// Get date value for today and Jan 1 this year at midnight
var oToday = new Date(oNow.getFullYear(), oNow.getMonth() + 1, oNow.getDate(), 0, 0, 0, 0)); // Today
var oStartYear = new Date(oNow.getFullYear(), 1, 1, 0, 0, 0, 0); // Jan 1 this year
// get day numbers from date time object for today and Jan 1
var fToday = Math.floor(Number(oToday) / fDay);
var fStartYear = Math.floor(Number(oStartYear / fDay);
var fOrdinalDate = fToday - fStartYear;
console.println("Today's Ordinal date is: " + fOrdinalDate); // Ordinal date of year

George Kaiser

TerryClawth
Registered: Jul 18 2008
Posts: 6
Whoaaaaaaaa!

both answers (George_Johnson & gkaiseril) look right, if I knew how to read them. I am but a lowly novice and these appear to be greek to me.If you have the time, could you please take me through the baby steps by writing out the code and explaining/commenting along the way so that I can learn what each line of code is doing?

My goal is simple - i want the field (on opening the form) to display the current date, but in numerical format.

thank you so much,
your humble beginner,

Terry
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Terry,

You need to clarify whether you want the Julian date (e.g., today = 2454668), or the day of the year (e.g., today = 202).

George
TerryClawth
Registered: Jul 18 2008
Posts: 6
hey george,

thanks for the quick response - to clarify - what i want is just the number of the date - like i get when i enter today's date 07/21/08 in a spreadsheet cell and format it for number. i get 39650 - how do i do that?

terry
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
In Excel, when you format a date as a number, it gives you the number of days since 1900-Jan-0. So, what you want is the number of days between now and 1900-Jan-0. No time to suggest the code now, but I'll check back later.

George
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Here is some code that will calculate the number you're after:


// There are 1000*60*60*24 = 86400000 milliseconds in one day
var ms_per_day = 86400000;

// Get the current date/time
var d1 = new Date();

// Get the number of milliseconds between
// Jan 1 1970 and the current date/time
var v1 = d1.valueOf();

// Calculate the number of days between current date
// and Jan 1 1970
var days_since_1970_01_01 = Math.floor(v1/ms_per_day);

// There are this many days between Jan 0 1900 and Jan 1 1970
var days_from_1900_01_00_to_1970_01_01 = 25569;

// Add the two differences in dates
var number_terry_wants = days_since_1970_01_01 + days_from_1900_01_00_to_1970_01_01;

// Now that we have the number,
// set the field value equal to this number
Sorry, someone else will have to show you how to do this last step.


This could be simplified by combining some of these steps, but you should get the idea.

George
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
More detail for the code I posted:

// define some date time constants
var fSec = 1000;
var fMin = 60 * fSec;
var fHr = 60 * fMin;
var fDay = 24 * fHr;
// get today's date time object
var oNow= new Date();
// Get date value for today and Jan 1 this year at midnight
// the passed parameters are: full year, month, date, hour, min, sec, milliseocnds
// the date parts are pulled form the date object and the month is adjusted from the zero based month numbering
// the time fields are forced to 0:00:00.000 or midnight
var oToday = new Date(oNow.getFullYear(), oNow.getMonth() + 1, oNow.getDate(), 0, 0, 0, 0)); // Today
// for the first day of the year use the current year, month of 1, date of 1, and midnight 0:00:00.000
var oStartYear = new Date(oNow.getFullYear(), 1, 1, 0, 0, 0, 0); // Jan 1 this year
// get day numbers from date time object for today and Jan 1
var fToday = Math.floor(Number(oToday) / fDay);
var fStartYear = Math.floor(Number(oStartYear / fDay);
var fOrdinalDate = fToday - fStartYear; // compute the difference between today and January 1 of this year
console.println("Today's Ordinal date is: " + fOrdinalDate); // Ordinal date of year

George Kaiser