Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > displaying the date in mysql format for insertion into db

Reply
Thread Tools

displaying the date in mysql format for insertion into db

 
 
libsfan01
Guest
Posts: n/a
 
      06-13-2006
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>

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      06-13-2006
libsfan01 wrote:
> 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:

<script type="text/javascript">


> 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.


--
Rob
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a date to mysql format Crustov Ruby 2 04-07-2009 08:07 PM
howto Date Time string from MYSQL to German Format sanitarysystems@googlemail.com Perl Misc 1 10-21-2007 12:54 PM
how can i use regular expressions to ensure a mysql format date entry in a text field? libsfan01 Javascript 8 10-12-2006 01:56 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM



Advertisments