Ok..codeless in the subject is a bit of a misnomer..there is code BUT there is no code-behind. Below I'll show you how to create an ordinal day and a military julian day utilizing the XPath.
Create a field in your InfoPath DataSource called Military Julian and paste the function into it's default value:
concat(substring(substring-before(now(), "-"), 3, 2), (((substring-before(substring-after(substring-after(now(), "-"), "-"), "T")) + floor((153 * ((substring-before(substring-after(now(), "-"), "-")) + 12 * (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12)) - 3) + 2) / 5) + (substring-before(now(), "-") + 4800 - (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12))) * 365 + floor((substring-before(now(), "-") + 4800 - (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12))) / 4) - floor((substring-before(now(), "-") + 4800 - (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12))) / 100) + floor((substring-before(now(), "-") + 4800 - (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12))) / 400) - 32045) - ((substring-before(substring-after(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-"), "T")) + floor((153 * ((substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) + 12 * (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12)) - 3) + 2) / 5) + (substring-before(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-") + 4800 - (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12))) * 365 + floor((substring-before(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-") + 4800 - (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12))) / 4) - floor((substring-before(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-") + 4800 - (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12))) / 100) + floor((substring-before(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-") + 4800 - (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12))) / 400) - 32045) + 1))
You now have the Military Julian in the format of YYNNN, where NNN is the Ordinal Day.
If you want only the Ordinal Day of the year use this function instead:
(((substring-before(substring-after(substring-after(now(), "-"), "-"), "T")) + floor((153 * ((substring-before(substring-after(now(), "-"), "-")) + 12 * (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12)) - 3) + 2) / 5) + (substring-before(now(), "-") + 4800 - (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12))) * 365 + floor((substring-before(now(), "-") + 4800 - (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12))) / 4) - floor((substring-before(now(), "-") + 4800 - (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12))) / 100) + floor((substring-before(now(), "-") + 4800 - (floor((14 - substring-before(substring-after(now(), "-"), "-")) / 12))) / 400) - 32045) - ((substring-before(substring-after(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-"), "T")) + floor((153 * ((substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) + 12 * (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12)) - 3) + 2) / 5) + (substring-before(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-") + 4800 - (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12))) * 365 + floor((substring-before(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-") + 4800 - (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12))) / 4) - floor((substring-before(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-") + 4800 - (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12))) / 100) + floor((substring-before(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-") + 4800 - (floor((14 - substring-before(substring-after(concat(string(substring(today(), 1, 4)), "-01-01T00:00:00"), "-"), "-")) / 12))) / 400) - 32045) + 1)
There seems to be quite a bit of confusion among the ranks as to what Julian is. Perhaps some of the confusion is my own lack of military background. My first spoken requirements were to create a Julian Day of the year for a form field. So I looked on wikipedia and discovered that the Julian Day Number is the number of days since Day 0 which is marked at 1/1/4713 BC Greenwich Time. Today, Oct. 15, 2010 that number is 2455485. That was fairly easy.
However the client actually uses a day which is not based on the Julian Date way back in 4713. It is based on the first day of the current year. It's called an ordinal day. Sticking the last 2 digits of the year on to the front of that number gives you a Military Julian day. The XPath is ugly but it works..even for Leap Years!
The formula above finds the julian day for the first of the current year (1/1/2010) and the julian day for the current day and subtracts the current Julian from the First of the year julian. 1 is added to the difference to arrive at the julian day of the year. I then concat the last 2 digits of the current year to the front and that's it. I store it in the dataset and then concat a time stamp to the end to get the tracking number in a format that is useful and generates a unique number.
Code behind does all this in about 2 lines of c# but then you need an admin to publish your form. That means making the client wait for who knows how long before they can see your forms.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment