Date conversion tools

gpm

Member
convert date between Julian foramt and calendar format.
 

Attachments

  • 124511-ShowJDate.zip
    5.1 KB · Views: 759
Hello GPM,

The tool is very good. But can you incorporate an alternate mechanism for picking up the date instead of the present one.

It would be good if you can put three buttons to advance day, month, year and three buttons to decreas day, month, year.
 
You can find a simple program to convert OW date from/To Julian format.
 

Attachments

  • 127251-data.zip
    6 KB · Views: 266
If you have Oracle, you can create two functions to convert OW dates:

CREATE OR REPLACE FUNCTION TO_JDECHAR (JDE_DATE IN CHAR)
RETURN VARCHAR2
IS
JDE_DATE1 NUMBER(6);
STR_ANNO CHAR(4);
STR_GIORNO CHAR(3);
STR_DATE DATE;
BEGIN
--
IF TO_NUMBER(JDE_DATE) = 0 THEN
JDE_DATE1 := 1;
ELSE
JDE_DATE1 := TO_NUMBER(JDE_DATE);
END IF;
--
STR_ANNO := TO_CHAR(1900 + TO_NUMBER(SUBSTR(LPAD(TO_CHAR(JDE_DATE1), 6, '0'), 1, 3)));
STR_GIORNO := SUBSTR(LPAD(TO_CHAR(JDE_DATE1), 6, '0'), 4, 3);
--
STR_DATE := TO_DATE(STR_ANNO || '-' || STR_GIORNO, 'YYYY-DDD');
--
RETURN(TO_CHAR(STR_DATE, 'DD/MM/YYYY'));
EXCEPTION
WHEN OTHERS THEN
RETURN('01/01/1500');
END TO_JDECHAR;
/

CREATE OR REPLACE FUNCTION TO_JDEDATE (STR_DATE IN VARCHAR2)
RETURN NUMBER
IS
JDE_DATE NUMBER;
BEGIN
--
SELECT
(TRUNC(TO_NUMBER(TO_CHAR(TO_DATE(STR_DATE, 'DD/MM/YYYY'), 'YYYY')) / 100) - 19) * 100000 +
TO_NUMBER(TO_CHAR(TO_DATE(STR_DATE, 'DD/MM/YYYY'), 'YY')) * 1000 +
TO_NUMBER(TO_CHAR(TO_DATE(STR_DATE, 'DD/MM/YYYY'), 'DDD'))
INTO
JDE_DATE
FROM
DUAL;
--
RETURN(JDE_DATE);
END TO_JDEDATE;
/

To convert the system date in OW Format:

select to_jdedate(to_char(sysdate,'DD/MM/YYYY')) as OWDate from dual

It's useful to update UPMJ field.

To convert 107333 OW date:

select to_jdechar(107333) from dual;

It's easy to use and very useful.
 
A System i (AS/400) SQL that does the conversion:

date(char(<JDE DATE>+1900000))
 
Hi Stewart,

I am interresting to integrate your jscript function/page to Road2fusion (http://www.road2fusion.com) but the link you posted does not work anymore.

Could U give us a new link or the jscript code?
 
Hi fmerloz,

The link worked with me. I just copied the source code of the page and pasted here. see if it helps u!!


<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>E1 Tips & Tricks - E1 Date Conversions</title>
<link href="datepicker.css" rel="Stylesheet" />
<script type="text/javascript" src="datepicker.js"></script>
<script language="javascript" type="text/javascript">
<!--

function btnSubmit_onclick() {
var ed = document.getElementById('e1date');
var et = document.getElementById('e1time');
var rdt = document.getElementById('realdate');

var h=0;
var m=0;
var s=0;

var t = new Array();

if (ed.value.length = 6 && ed.value != '') {
//*** the first three digits are the year
var y = ed.value.substr(0,3);
//*** add 1900 to the year (this looks to be a Y2K fix
y = parseFloat(1900 + parseFloat(y));
//*** the second set of 3 digits is the number of days sinse January 1
var days = ed.value.substr(3,3);
//*** subtract a day because of base zero days
days = parseFloat(days-1);
//*** process the time
t = processTime(et.value);
//*** create the date object as of January 1 for the given year
var d = new Date(y,0,1,t[0],t[1],t[2]);
//*** add the days to the January 1 date
d.setDate(d.getDate()+days);
//*** return the "real" date
rdt.innerHTML = d.toString();
}
else {
t = processTime(et.value);
rdt.innerHTML = f2d(t[0]).concat(':',f2d(t[1]),':',f2d(t[2]));
}
}
function f2d(n) {
//*** force 2 digits
return (n.length != 2)? '0'+n : n;
}
function processTime(arg) {
var h=0;
var m=0;
var s=0;

if (arg.length = 6 && arg != '') {
var s = arg.substr(arg.length-2,2);
var m = arg.substr(arg.length-4,2);
var h = arg.substr(0,arg.length-4);
}

var t = new Array(h,m,s);
return t;
}

function btnGo9Digit_onclick() {
var t9d = document.getElementById('txt9Digit').value;
if (t9d.length > 0) {
/*** replace all instances of a comma ***/
t9d=t9d.replace(/,/g,'');
/*** convert t9d from minutes to milliseconds ***/
t9d = parseFloat(t9d)*1000*60;
var r9d = document.getElementById('result9DigitDate');
/*** get a new date object ***/
var s = new Date();
/*** set the date object to the new time ***/
s.setTime(t9d);
r9d.innerHTML = s.toString();
}

}

function btnGetRealDate_onclick() {
var rd2 = document.getElementById('realdate2').value;
var e19dd = document.getElementById('e19digitdate');
var e16dd = document.getElementById('e16digitdate');
var e16dt = document.getElementById('e16digittime');
var ddlHour = document.getElementById('ddlHour');
var ddlMinute = document.getElementById('ddlMinute');
var ddlSecond = document.getElementById('ddlSecond');

if (rd2.length > 0) {
var d = Date.parse(rd2 + ' ' + ddlHour.value + ':' + ddlMinute.value + ':' + ddlSecond.value); /*** given date in milliseconds ***/
/*** get the 9 digit date ***/
e19dd.innerHTML = d/1000/60; /*** convert from milliseconds to minutes ***/

var d2 = new Date();
d2.setTime(d);
d2.setHours(ddlHour.value,ddlMinute.value,ddlSecond.value,0);

/*** get 6 digit date ***/
var y2 = d2.getFullYear()-1900;
var Y = d2.getFullYear(), M = d2.getMonth(), D = d2.getDate();
var doy = 1 + (Date.UTC(Y, M, D) - Date.UTC(Y, 0, 1)) / 86400000;
doy = doy.toString();
while (doy.length < 3){
var z = '0';
doy = z.concat(doy);
}
var e16d = '';
e16d = e16d.concat(y2);
e16dd.innerHTML = e16d.concat(doy);

/*** get 6 digit time ***/
e16dt.innerHTML = force2char(d2.getHours()) + force2char(d2.getMinutes()) + force2char(d2.getSeconds());
}
}
// -->
</script>
<style type="text/css">
p { margin-left: 10px; }
h4 { margin-left: 5px; font-weight: bold; }
select.time { width: 40px; }
</style>
</head>

<body>
<div style="border: solid 1px #c0c0c0;background: #e7e7e7;">
<div style="background-color: #808080; color: #fff; font-weight: bold;"> Get the real date from E1 6 digit date and/or time:</div>

<p>E1 Date:
<input id="e1date" type="text" maxlength="6" size="10" /> E1 Time:
<input id="e1time" maxlength="6" size="10" type="text" /></p>
<p>Real Date:<br /><br />
<span id="realdate" style="margin-left:20px;"> </span></p>
<p><input id="btnSubmit" type="button" value="Get Date!" onclick="return btnSubmit_onclick()" /><br />
</p>
</div>
<br />
<div style="border: solid 1px #c0c0c0;background: #e7e7e7;">
<div style="background-color: #808080; color: #fff; font-weight: bold;"> Get the real date from E1 9 digit date/time:</div>

<p>E1 Date/Time: <input id="txt9Digit" type="text" maxlength="10" size="10" /></p>
<p>Real Date:<br /><br />
<span id="result9DigitDate" style="margin-left:20px;"> </span></p>
<p>
<input id="btnGo9Digit" type="button" value="Get 9 Digit Date!" onclick="return btnGo9Digit_onclick()" />
</p>
</div>
<br />
<div style="border: solid 1px #c0c0c0;background: #e7e7e7;">

<div style="background-color: #808080; color: #fff; font-weight: bold;"> Get the E1 date from the real date/time:</div>
<p>Real Date: <input id="realdate2" name="realdate2" type="text" maxlength="10" size="10" /><input type="button" value="select" onclick="displayDatePicker('realdate2');"><br />
Real Time (hh mm ss): <select id="ddlHour" class="time"></select> <select id="ddlMinute" class="time"></select> <select id="ddlSecond" class="time"></select></p>
<hr style="display: block; width: 100%;" size="5px" />
<p>
E1 9 Digit Date: <span id="e19digitdate"> </span><br /><br />
E1 6 Digit Date: <span id="e16digitdate"> </span><br /><br />

E1 6 Digit Time: <span id="e16digittime"> </span></p>
<p>
<input id="btnGetRealDate" type="button" value="Get E1 Dates!" onclick="return btnGetRealDate_onclick()" />
</p>
</div>
<script type="text/javascript">
<!--
function popSelects() {
/*** write out the options for the <select> elements ***/
var ddlHour = document.getElementById('ddlHour');
var ddlMinute = document.getElementById('ddlMinute');
var ddlSecond = document.getElementById('ddlSecond');
var h, m, s;
for (h=0;h<24;h++) {
var o = new Option(force2char(h),force2char(h));
try {
ddlHour.add(o,null); // standards compliant
}
catch(ex) {
ddlHour.add(o); // IE only
}
}
for (m=0;m<60;m++) {
var o = new Option(force2char(m),force2char(m));
try {
ddlMinute.add(o,null); // standards compliant
}
catch(ex) {
ddlMinute.add(o); // IE only
}
}
for (s=0;s<60;s++) {
var o = new Option(force2char(s),force2char(s));
try {
ddlSecond.add(o,null); // standards compliant
}
catch(ex) {
ddlSecond.add(o); // IE only
}
}
}
function force2char(arg) {
var n = arg.toString();
while (n.length < 2){
var z = '0';
n = z.concat(n);
}
return n;
}
popSelects();
//-->
</script>
</body>
</html>
 
Hi gov,

it is really cool but I just have a very simple issue.. I do not have the js libray for the date picker (datepicker.js)! Could U post it here?
 
Back
Top