trying to format the YYYYMMDDHHMMSS variable that i pull out of my MySQL db.
can't figure out how to take this variable (let's say $row['mydate'] = "YYYYMMDDHHMMSS") and break it up with PHP into separate variables i can use.
anybody?
thx!
o
date() MySQL to PHP
Moderator: General Moderators
tsabar,
Try this function:-
Regards
Hebbs
Try this function:-
Code: Select all
function timestampToUnix( $t ) {
$YYYY = $MM = $DD = $hh = $mm = 0;
$YYYY = "$t[0]$t[1]$t[2]$t[3]";
$MM = "$t[4]$t[5]";
$DD = "$t[6]$t[7]";
$hh = "$t[8]$t[9]";
$mm = "$t[10]$t[11]";
return strtotime("$DD/$MM/$YYYY $hh:$mm:00");
}Regards
Hebbs
date() function
i got the date function, i just don't get how to have the date() function use the variable i give it ("YYYYMMDDHHMMSS") instead of today's date.
can that be done?
can that be done?
sure, just use strtotime() to change the string format to a useable "time" format for php.
ex:
ex:
Code: Select all
$mydate = "2005-01-04 10:00:30";
$day = date("d",strtotime($mydate));
$year = date("Y",strtotime($mydate));
$month = date("m",strtotime($mydate));
//etcCode: Select all
SELECT UNIXTIMESTAMP(datecolumn) AS unixtime FROM table