simon551 Posted June 20, 2007 Share Posted June 20, 2007 is there a way to change the format of a date that is submitted through an html form? example: I have a form with a date field that accepts a standard U.S. date format of (%m/%d/%Y) but then when this: ($_POST['fdate'], "date") occurs I'd like it to take a date value of (%Y-%m-%d) so that the server will handle it. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/ Share on other sites More sharing options...
trq Posted June 20, 2007 Share Posted June 20, 2007 date(). Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278602 Share on other sites More sharing options...
Caesar Posted June 20, 2007 Share Posted June 20, 2007 Insert the dates as a timestamp into an INT column/field. <?php $mydate = 'January 15, 2005'; //Assuming that is the date submitted in $_POST['fdate'] or whatever $formatit = strtotime($mydate); ?> When you query for dates later..you can format easily for display....in any format you want using the date() function. Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278603 Share on other sites More sharing options...
trq Posted June 20, 2007 Share Posted June 20, 2007 Insert the dates as a timestamp into an INT column/field. Do not store them in an INT type field. Use a timestamp type field. Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278607 Share on other sites More sharing options...
simon551 Posted June 20, 2007 Author Share Posted June 20, 2007 I tried this: $date= date($_POST['fdate']); when I enter enter 06/20/2007 and submit, the resulting entry is 0000-00-00 just to be sure, if I enter 2007-06-20, and submit then it submits fine. what am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278632 Share on other sites More sharing options...
chigley Posted June 20, 2007 Share Posted June 20, 2007 $timestamp = strtotime($_POST["date"]); Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278636 Share on other sites More sharing options...
simon551 Posted June 20, 2007 Author Share Posted June 20, 2007 so in order to accomplish this, I have to change the field type in my database to TIMESTAMP? Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278640 Share on other sites More sharing options...
chigley Posted June 20, 2007 Share Posted June 20, 2007 How do you want to store them? You can store them in any format you want Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278641 Share on other sites More sharing options...
simon551 Posted June 20, 2007 Author Share Posted June 20, 2007 date. i.e. 2007-06-20 I'm trying to convert something like 06/20/2007 to 2007-06-20 which is what my mysql database will accept in a "date" field. I don't understand, are you saying I can do that with the strtotime function? Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278648 Share on other sites More sharing options...
chigley Posted June 20, 2007 Share Posted June 20, 2007 <?php $date1 = "06/20/2007"; $timestamp = strtotime($date1); $date2 = date("Y-m-d", $timestamp); echo "{$date1} converted to {$date2}"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278653 Share on other sites More sharing options...
simon551 Posted June 20, 2007 Author Share Posted June 20, 2007 THANK YOU!! Quote Link to comment https://forums.phpfreaks.com/topic/56413-solved-convert-date-in-php/#findComment-278688 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.