Hi,
I have a problem with the date.
I am getting date as string from file.I would like to convert this string to Mysql date.I dont want to insert date as a varchar.
I did like ,,it is not working..
$phpdate1='10/02/2000';
$mysqldate=date('y-m-d',$phpdate1);
echo $mysqldate;
how to convet string date to Mysqldate
Moderator: General Moderators
Re: how to convet string date to Mysqldate
What exactly you want to do with the date field??
Why you don't want to use VARCHAR??
You can use STR_TO_DATE(date,dateformat) function in mysql to convert a string into date..
Why you don't want to use VARCHAR??
You can use STR_TO_DATE(date,dateformat) function in mysql to convert a string into date..
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: how to convet string date to Mysqldate
I prefer dates/datetimes over strings as dates any day. One reason is conditional logic. Is "01/01/2009" > "10/01/2000" ? Not if they're strings, it's not. So, rather than adding a layer of conversion on top of your queries to compare dates, if you can, store them as dates instead of strings.
Plus, your usage here is wrong, varma457:
The date() function accepts a second parameter as a time (int) value. Try this instead:
Plus, your usage here is wrong, varma457:
Code: Select all
$phpdate1='10/02/2000';
$mysqldate=date('y-m-d',$phpdate1);
echo $mysqldate;Code: Select all
$phpdate1='10/02/2000';
$mysqldate = date('Y-m-d',strtotime($phpdate1));
echo $mysqldate;Re: how to convet string date to Mysqldate
@johniem
I would like to put DATE descending order..
IS IT POSSIBLE WITH VARCHAR FORMAT...
I would like to put DATE descending order..
IS IT POSSIBLE WITH VARCHAR FORMAT...
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: how to convet string date to Mysqldate
not without converting it.varma457 wrote:@johniem
I would like to put DATE descending order..
IS IT POSSIBLE WITH VARCHAR FORMAT...