mdemetri2 Posted May 14, 2014 Share Posted May 14, 2014 Hi I have a javascript calendar that populates a form field (survey) in the format of dd/mm/yyyy. I don't know of a method to change the format in the calendar. So, I would like the format to be changed at the point the form is submitted and the date is used to update a record. I have tried to amend the portion of the update script for the survey field to change the format as part of it submitting the change. I used this line: GetSQLValueString(date("Y-m-d, strtotime("$_POST['survey']), "text") but I'm not getting the expected results, essentially from the text field entry format of dd/mm/yyyy I want Y-m-d Is this possible? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/288478-changing-the-format-of-a-date-in-_post/ Share on other sites More sharing options...
Barand Posted May 14, 2014 Share Posted May 14, 2014 Look it up in the documentation for your particular datepicker. If there is none, use one that has. http://api.jqueryui.com/datepicker/#option-dateFormat PS: I prefer to set datepickers to use "31 Jan 2014" format as it is clear to the user, unambiguous and recognised by strtotime() Link to comment https://forums.phpfreaks.com/topic/288478-changing-the-format-of-a-date-in-_post/#findComment-1479427 Share on other sites More sharing options...
mdemetri2 Posted May 16, 2014 Author Share Posted May 16, 2014 thanks for the reply Barand. I was trying to avoid replacing what I have with a new type of date picker. Anyone have any ideas on whether what I'm asking is possible? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/288478-changing-the-format-of-a-date-in-_post/#findComment-1479713 Share on other sites More sharing options...
Barand Posted May 16, 2014 Share Posted May 16, 2014 Then if looking up the documentation for your calendar fails you will have to look through the js code for where the format is specified. Link to comment https://forums.phpfreaks.com/topic/288478-changing-the-format-of-a-date-in-_post/#findComment-1479715 Share on other sites More sharing options...
Barand Posted May 17, 2014 Share Posted May 17, 2014 If changing the js code doesn't work, you can always reformat it in PHP $calendar_date = '17/05/14'; $dt = DateTime::createFromFormat('d/m/y', $calendar_date); $formatted_date = $dt->format('Y-m-d'); echo $formatted_date; //--> 2014-05-17 Link to comment https://forums.phpfreaks.com/topic/288478-changing-the-format-of-a-date-in-_post/#findComment-1479859 Share on other sites More sharing options...
mdemetri2 Posted May 20, 2014 Author Share Posted May 20, 2014 I have tried the implement that unsuccessfully. I needed it as part of a post - when the form gets submitted. I will keep trying, thanks. Link to comment https://forums.phpfreaks.com/topic/288478-changing-the-format-of-a-date-in-_post/#findComment-1480136 Share on other sites More sharing options...
Jacques1 Posted May 20, 2014 Share Posted May 20, 2014 Well, saying that you couldn't implement this is rather vague. What exactly is the problem? Using DateTime to convert the format is a good solution and works perfectly fine. If you're not getting the expected result, you've made a mistake. But of course we can't help you with that unless you post your code and describe the specific problem. Link to comment https://forums.phpfreaks.com/topic/288478-changing-the-format-of-a-date-in-_post/#findComment-1480138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.