displaying the date in mysql format for insertion into db

L

libsfan01

HI all!

ive need to format the date (variable "tomorrow") in this form to mysql
format yyyy-mm-dd can anyone please show me how to amend my script?

regards

Marc



<script language="javascript">

function showDate(thisObj){
/* create a Date object using the system clock */
today=new Date();
td = today.getDate();
tm = today.getMonth();
ty = today.getFullYear();
tomorrow=new Date(ty,tm,td+1)

/* convert contents to string and place in control */
document.getElementById(thisObj).value=tomorrow;
}



</script>
<body onLoad="showDate('date');">



<input id="date" type="text" readonly="readonly" />

</body>
 
R

RobG

libsfan01 said:
HI all!

ive need to format the date (variable "tomorrow") in this form to mysql
format yyyy-mm-dd can anyone please show me how to amend my script?

regards

Marc



<script language="javascript">

The language attribute is deprecated, type is required:

function showDate(thisObj){
/* create a Date object using the system clock */
today=new Date();

Always use var to keep variables local unless you really do need globals:

var today = new Date();

And tomorrow is:

var x = new Date();
x.setDate(x.getDate() + 1);


Now x is tomorrow's date[1]. You may need to be careful around
midnight, getting today's date at 23:59:59 may result in tomorrow being
today very soon. :)
td = today.getDate();
tm = today.getMonth();
ty = today.getFullYear();
tomorrow=new Date(ty,tm,td+1)

/* convert contents to string and place in control */
document.getElementById(thisObj).value=tomorrow;

function addZ(n){
return (n<10)? '0'+n : ''+n;
}

...value = x.getFullYear()
+ '-' + addZ(x.getMonth()+1)
+ '-' + addZ(x.getDate());


1. Creating a date of say - new Date('2006/06/31') - will result in 1st
of July, or - new Date('2006/06/32') - 2nd of July.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top