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 formating variable
Moderator: General Moderators
-
timclaason
- Forum Commoner
- Posts: 77
- Joined: Tue Dec 16, 2003 9:06 am
- Location: WI
Date
feyd | Please use
feyd | Please use
Code: Select all
,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 explodeCode: 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
,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]Code: Select all
date("Y-m-d", strtotime("2006-5-1"));
//output: 2006-05-01