LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   html form current datetime (https://www.linuxquestions.org/questions/programming-9/html-form-current-datetime-55153/)

david_ross 04-16-2003 03:16 PM

Hopefully this time!
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Current Date and Time</TITLE>
</HEAD>
<BODY>
<FORM name="form1"><INPUT name="box1" type="text"><INPUT name="box2" type="text"></FORM>

<SCRIPT type="text/javascript" language="JavaScript">

time = new Date();
year = new String(time.getYear());
if(navigator.appName != "Microsoft Internet Explorer"){year = (year*1)+1900}
month = new String((time.getMonth() + 1));
date = new String(time.getDate());
hours = new String(time.getHours());
mins = new String(time.getMinutes());
secs = new String(time.getSeconds());
if(mins.length<2){mins = "0"+mins}
if(secs.length<2){secs = "0"+secs}
if(month.length<2){month = "0"+month}
if(date.length<2){date  = "0"+date}
if(mins < 10){minstwo = new String((mins*1)+50)}
else{minstwo = new String((mins*1)-10)}
if(minstwo.length<2){minstwo = "0"+minstwo}

// Config Starts
box1format = year+"-"+month+"-"+date+" "+hours+":"+mins+":"+secs;
box2format = year+"-"+month+"-"+date+" "+hours+":"+minstwo+":"+secs;
document.form1.box1.value = box1format;
document.form1.box2.value = box2format;
// Config Ends

</SCRIPT>
</BODY>
</HTML>


meluser 04-16-2003 03:20 PM

excellent, one final problem


when the time is 21:05:00 and -10 is substracted, then we get 21:-5:00

i tried by setting 10 to 30, and this is the reuslts:

2003-04-16 21:20:19
2003-04-16 21:-10:19


thanks once again

david_ross 04-16-2003 03:34 PM

Here you go:
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Current Date and Time</TITLE>
</HEAD>
<BODY>
<FORM name="form1"><INPUT name="box1" type="text"><INPUT name="box2" type="text"></FORM>

<SCRIPT type="text/javascript" language="JavaScript">

time = new Date();
year = new String(time.getYear());
if(navigator.appName != "Microsoft Internet Explorer"){year = (year*1)+1900}
month = new String((time.getMonth() + 1));
date = new String(time.getDate());
hours = new String(time.getHours());
mins = new String(time.getMinutes());
secs = new String(time.getSeconds());
if(mins.length<2){mins = "0"+mins}
if(secs.length<2){secs = "0"+secs}
if(month.length<2){month = "0"+month}
if(date.length<2){date  = "0"+date}
if(mins < 10){
minstwo = new String((mins*1)+50);
if(hours == "00"){
hourstwo = "23";
}
else{
hourstwo = new String((hours*1)-1);
}
}
else{minstwo = new String((mins*1)-10)}
if(minstwo.length<2){minstwo = "0"+minstwo}

// Config Starts
box1format = year+"-"+month+"-"+date+" "+hours+":"+mins+":"+secs;
box2format = year+"-"+month+"-"+date+" "+hourstwo+":"+minstwo+":"+secs;
document.form1.box1.value = box1format;
document.form1.box2.value = box2format;
// Config Ends

</SCRIPT>
</BODY>
</HTML>


meluser 04-16-2003 03:41 PM

thanks, but still problem:


2003-04-16 21:41:01
2003-04-16 21:-9:01

i changed the -10 to -50, to test, and here is the results!!!

david_ross 04-16-2003 03:50 PM

Of course it will it is only set to take of 10 minute - if you want to take of more you will need to modify the +50 argument too

meluser 04-16-2003 03:54 PM

ok, excellent. about the pop up calendar, is there any chance of helping me out please. i have a pop up one that only has the date. please.

david_ross 04-16-2003 03:56 PM

What EXCATLY do you want?

meluser 04-16-2003 03:59 PM

Thanks,

a pop up calendar, that helps the user to input the date and time, instead of having to type 0000-00-00 00:00:00, he would simply click on this javascript pop up calendar, that displays, a list of options for the user to select!!!!

http://www.dynamicdrive.com/dynamici...opcalendar.htm

but with the time as well.

i really appeciate your help, thanks a million

meluser 04-16-2003 04:00 PM

thanks.

there is this one as well:

http://www.dynamicdrive.com/dynamici...pcalendar2.htm

david_ross 04-16-2003 04:24 PM

Well! The first one failed with Mozilla and the second one worked but there was no time. Why do you need them to select a time if it is automatically created? Can you not just use drop down elements in forms?

meluser 04-16-2003 04:41 PM

hi

The reason for this, is because i am using the form values to query MySQL. i require date and time to query data. i know the second one does date only, but i would like to have time as well.

cheers

david_ross 04-16-2003 05:05 PM

Quote:

Originally posted by david_ross
Can you not just use drop down elements in forms?
Is there a reason that this isn't viable?

meluser 04-16-2003 06:51 PM

hi

how do you do that?


All times are GMT -5. The time now is 12:15 AM.