Page 1 of 1
date formating variable
Posted: Fri Nov 17, 2006 8:45 am
by hmsg
Hi.
I have a variable $d that contain a date but in this format ex.: 2006-5-1 , but now i need to make a select to a mysql DB the problem is that in mysql the date type is 2006-05-01, how can i solve this. Is it possible use the function date() of php like this: date("Ymd", $d);
Thank for anyone help
HMSG
Date
Posted: Fri Nov 17, 2006 9:01 am
by timclaason
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
You could do an explode
Code: Select all
$newdate = explode("-", $d);
$newyear = $newdate[0];
for($index = 1; $index < 3; $index++) {
if($newdate[$index] < 10) {
$newdate[$index] = "0" . $newdate[$index];
}
}
$formattednewdate = $newdate[0] . "-" . $newdate[1] . "-" . $newdate[2];
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Fri Nov 17, 2006 9:04 am
by JayBird
Code: Select all
date("Y-m-d", strtotime("2006-5-1"));
//output: 2006-05-01