473,473 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

displaying the date in mysql format for insertion into db

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>

Jun 13 '06 #1
1 1523
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
Jun 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul Beckett | last post by:
I have successfully used strtotime to format the date on a webpage that is pulled form a MySQL database in the form yyyy-mm-dd. However, in another part of the webpage, I have to insert another...
8
by: paul | last post by:
Hi everyone, I've just started using php, and although I am very impressed by it, there are some things with which I am confounded! What I'm trying to do is read in a Date from a mySql database...
1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
2
by: Paul | last post by:
I am trying to insert a date into a mysql table but everytime I attempt it the date field is always empty. The field is of Date type and the date in code is in European format dd/mm/yyyy. ...
1
by: Rotsj | last post by:
Hi, i'm using visual foxpro 9 with a mysql 5 database, for direct access to my database i use navicat. In visual foxpro i've set my date format to dd-mm-yyyy, also i did this in navicat. However...
9
by: Bosconian | last post by:
I must be having a brain freeze because I can't figure out how to display dates older than 1970. I have birth dates stored in MySQL as "date" data types (exp. 1955-04-06). I'd like to display as...
3
by: dave | last post by:
I need to compute an expiration date based on the number of hours, days, or months purchased. The expiration date needs to be expressed in minutes something like '1260481600'. How can I get the...
2
by: Colleen Robledo, MLIS | last post by:
Hello, I'm still pretty new to PHP and MySQL, and have a PHP scripting question. If I'm querying DATE info from a MySQL database, and displaying it with PHP echo statements... is there a PHP...
9
by: TC | last post by:
Hi. I have some ASP written in VB.net which is currently installed on a customers server. The asp connects to a local MySql database and retrieves data for the customers customers. If you see...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.