View Full Version : simple datetime help
Roost3r
09-19-2002, 05:18 PM
can someone plz tell me how to format the dates that i get from my website... currently it shows as 020917 but i want it to show like this 09/17/02
thanks
See if this helps you:
<script>
var mydate=new Date()
var year=mydate.getYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (year==2002){
year="02"}
//-->
</SCRIPT>
<script>
document.write("<b>"+(month+1)+"/ "+daym+"/ "+year+"</b>")
</script>
Roost3r
09-19-2002, 06:47 PM
er i already have the dates in my mysql database
mordred
09-19-2002, 07:51 PM
SELECT DATE_FORMAT(dateFieldName, "%d/%m/%Y") ....
Provided you actually store the date in a DATETIME field.
BTW: Where's the PHP question? MySQL has it's own forum.
Roost3r
09-19-2002, 09:13 PM
... im sure theirs a way to format the datetime field from my mysql db using php :thumbsup: k thx
Spookster
09-19-2002, 09:16 PM
This could be formatted using either PHP or MySQL. Which way would depend on where the date is coming from. If it is a date generated and/or stored in the database then use SQL to format it. If you are just wanting to display like the current date or something then you would use PHP like so:
<?php
$today = date("F j, Y");
print "$today";
?>
Which would display todays date as:
September 19, 2002
mordred
09-19-2002, 10:46 PM
To expand on what Spookster said and to prevent future confusion as to how to employ MySQLs DATE_FORMAT() function and PHPs date() function, here are the links to the entries in the manuals:
http://www.php.net/manual/en/function.date.php
http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#Date_and_time_functions
Observe that the usage of both functions is similar, but the specifiers in the format string are different!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.