Click to See Complete Forum and Search --> : According to my php-output dates, we should just be parking the VW van.
calliepeck
02-10-2006, 06:27 AM
Ok, so I've been learning and hacking and hacking and learning, and have managed to put out some decent, validated code along the way. Making progress at least.
Hitting a very minor roadblock right now though. I can't get my date fields to output the date in a readable format *with the correct date*. My sql field is set to date and in the correct YYYY-MM-DD format, but when I put in the query SELECT DATE_FORMAT($date, '%D %M, %Y'), it comes out with January 1, 1970. Have checked and double checked that the database contains the right numbers. Any idea what's up?
Cheers.
jogol
02-10-2006, 06:51 AM
i use dateconvert.php by Chris McKee.
<?php function dateconvert($date,$func) {
if ($func == 1){ //insert conversion
list($day, $month, $year) = split('[/.-]', $date);
$date = "$year-$month-$day";
return $date;
}
if ($func == 2){ //output conversion
list($year, $month, $day) = split('[-.]', $date);
$date = "$day.$month.$year";
return $date;
}
} ?>
$date = $row[date]; //your mysql date
$realdate = dateconvert($date,2);
e.g.
$date = 2006-02-10
$realdate = 10.02.2006
calliepeck
02-10-2006, 07:35 AM
Thanks so much, jogol. I've got it working in numeric format. Is there any way now to get it into expanded version (i.e., February 10, 2006)?
aaronbdavis
02-10-2006, 07:36 AM
"SELECT DATE_FORMAT($date, '%D %M, %Y')"
// $date should be date (assuming date is the name of the field you are querying
"SELECT DATE_FORMAT(date, '%D %M, %Y')"
When you put in $date, you are telling PHP to evaluate a variable before running the query. If the variable hasn't been set to a value, it is assumed to be zero. For dates, zero = Jan 1, 1970 (dates are actually counted in miliseconds from that date).
NogDog
02-10-2006, 07:59 AM
Possibly what you want is the column name for your date field instead of the PHP varialbe $date?
SELECT DATE_FORMAT(`date_column`, '%D %M, %Y') FROM `table_name`...
aaronbdavis
02-10-2006, 09:27 AM
also, if you are simply trying to display the current date, you do not need to use MySQL at all. Just use PHP's date() (http://php.net/date) function. For example, the format you are using would be $today = date("F d, Y");