hmark Posted January 13, 2010 Share Posted January 13, 2010 Hello. I simply wanted to add a column for date. I would like to have user enter MMM-YY. For example APR-09. How do i format the field? mysql> alter table experts add column best_est_date date(mmm-yy); This doesn't work. Thank you. Link to comment https://forums.phpfreaks.com/topic/188391-date-field/ Share on other sites More sharing options...
AngelG107 Posted January 14, 2010 Share Posted January 14, 2010 Well, I'm not sure about what you're looking for, but here's a small example about how to format the current date like that. <?php $year = date("Y"); $month = date("m"); $year_formated = $year[2] . $year[3]; if($month == "01"){$month_formated = "Jan";} if($month == "02"){$month_formated = "Feb";} if($month == "03"){$month_formated = "Mar";} if($month == "04"){$month_formated = "Apr";} if($month == "05"){$month_formated = "May";} if($month == "06"){$month_formated = "Jun";} if($month == "07"){$month_formated = "Jul";} if($month == "08"){$month_formated = "Aug";} if($month == "09"){$month_formated = "Sep";} if($month == "10"){$month_formated = "Oct";} if($month == "11"){$month_formated = "Nov";} if($month == "12"){$month_formated = "Dec";} $date_formated = $month_formated . "-" . $year_formated; echo $date_formated; // THERE YOU GO, YOU HAVE THE DATE FORMATED LIKE THAT IN THE date_formated VARIABLE ?> I hope it helps you out somehow. If you need more help, just send me a message. Link to comment https://forums.phpfreaks.com/topic/188391-date-field/#findComment-995071 Share on other sites More sharing options...
fenway Posted January 16, 2010 Share Posted January 16, 2010 Don't do that... use a proper date picker, and have it submit YYYY-MM-DD to the database. Link to comment https://forums.phpfreaks.com/topic/188391-date-field/#findComment-995951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.