| | |
convert date(string) to date (date time)
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2006
Posts: 11
Reputation:
Solved Threads: 0
please,help me i want to convert date(string) to date (date time), this date i make setting for day with one (constant)
to use it in database i write in html
<html>
<head>
<SCRIPT type="text/javascript">
function startDate()
{
var d=new Date()
var y=d.getYear()
var m=d.getMonth()+1
var day=1
var date=m+"/"+day+"/"+y
document.write("date is: "+date)
// OUTPUT WILL BE 4/1/2007 THIS IS STRING I NEEED IT DATETIME //
var dat=Date.parse(date);
document.write("date is: "+dat)
// OUTPUT WILL BE 1175378400000 //
// PLEASE HELP ME TO GET TRUE RESULT //
}
</SCRIPT>
</head>
<body onload="startDate()" >
</body>
</html>
to use it in database i write in html
<html>
<head>
<SCRIPT type="text/javascript">
function startDate()
{
var d=new Date()
var y=d.getYear()
var m=d.getMonth()+1
var day=1
var date=m+"/"+day+"/"+y
document.write("date is: "+date)
// OUTPUT WILL BE 4/1/2007 THIS IS STRING I NEEED IT DATETIME //
var dat=Date.parse(date);
document.write("date is: "+dat)
// OUTPUT WILL BE 1175378400000 //
// PLEASE HELP ME TO GET TRUE RESULT //
}
</SCRIPT>
</head>
<body onload="startDate()" >
</body>
</html>
•
•
Join Date: Mar 2007
Posts: 83
Reputation:
Solved Threads: 2
OK, it seems you posted twice this time with more detail... this should be posted to the Javascript lists rather than JSP lists... BUT, a date object, or datetime is just a long numberic value... counting (usually) seconds or militseconds sine the "Epoc" time... usually Jan, 1 1970 00:00:00...
You have actually got what you need for a database, which you do an insert SQL with passing the long value to a datetime column, depending upon the database should result int he correct DB value being saved... you are confusing, I think, human readability with machine readability...
The first one you show, your string is human readable, while the number is how the machine will see it when it is properly converted to a date object...
In Java, when we have a date object which represents a given date, the toString will show it as 2007-04-01 while we insert it into the DB as a timestamp with setTimestamp(1, date.getTime())...
The getTime() method of the Date object returns a "long" with is just a number with lots of places... this is what the DB requires to understand the time....
Peace,
You have actually got what you need for a database, which you do an insert SQL with passing the long value to a datetime column, depending upon the database should result int he correct DB value being saved... you are confusing, I think, human readability with machine readability...
The first one you show, your string is human readable, while the number is how the machine will see it when it is properly converted to a date object...
In Java, when we have a date object which represents a given date, the toString will show it as 2007-04-01 while we insert it into the DB as a timestamp with setTimestamp(1, date.getTime())...
The getTime() method of the Date object returns a "long" with is just a number with lots of places... this is what the DB requires to understand the time....
Peace,
•
•
Join Date: Jun 2007
Posts: 1
Reputation:
Solved Threads: 0
hi,
how can i convert
var dat=Date.parse(date);
("dat" has 1175378400000)
dat again to date (i.e.,4/1/2007)
thanx in advance
how can i convert
var dat=Date.parse(date);
("dat" has 1175378400000)
dat again to date (i.e.,4/1/2007)
thanx in advance
•
•
•
•
please,help me i want to convert date(string) to date (date time), this date i make setting for day with one (constant)
to use it in database i write in html
<html>
<head>
<SCRIPT type="text/javascript">
function startDate()
{
var d=new Date()
var y=d.getYear()
var m=d.getMonth()+1
var day=1
var date=m+"/"+day+"/"+y
document.write("date is: "+date)
// OUTPUT WILL BE 4/1/2007 THIS IS STRING I NEEED IT DATETIME //
var dat=Date.parse(date);
document.write("date is: "+dat)
// OUTPUT WILL BE 1175378400000 //
// PLEASE HELP ME TO GET TRUE RESULT //
}
</SCRIPT>
</head>
<body onload="startDate()" >
</body>
</html>
![]() |
Similar Threads
- convert int to string (C)
- How do I convert a vector to a String array ? (Java)
- Validate the input date by comparing it with current year using Date function Date(Y) (PHP)
- inputing system("date /t") and system("time /t") into a file (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: applets
- Next Thread: expanding table in flash/javascript required
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets array blackjack browser captcha captchaformproblem cart checkbox child class close codes date debugger dependent developer disablefirebug dom editor element embed engine events explorer ext file firefox flash form forms game getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl maps marquee masterpage math matrixcaptcha media mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php position post programming prototype rated redirect runtime safari scale scriptlets scroll search security session shopping size software sources star stars stretch synchronous toggle tweet unicode variables web webservice window wysiwyg \n





