NiallThistle Posted September 25, 2011 Share Posted September 25, 2011 I'm going round in circles with this one, but I have a feeling that the answer is obvious. I have POST information that I want to use as a date and display it using date format, but I don't know how to The POST data outputs the following: 2011-9-23 Assuming I have defined $date as the posted data from the previous form, how do I write some code to tell it to output it as September 23, 2011, or just Sept 2011? Quote Link to comment https://forums.phpfreaks.com/topic/247860-date-formatting/ Share on other sites More sharing options...
Xpluration Posted September 25, 2011 Share Posted September 25, 2011 Try this: http://www.php.net/manual/en/datetime.createfromformat.php Quote Link to comment https://forums.phpfreaks.com/topic/247860-date-formatting/#findComment-1272727 Share on other sites More sharing options...
NiallThistle Posted September 25, 2011 Author Share Posted September 25, 2011 I was actually reading that very site about an hour ago. Can't make head nor tail of it, in terms of context, how I should adapt what I have. Essentially what I have just now is: echo"$date"; And that outputs the basic SQL entry format of '0000-00-00'. Can anyone suggest a basic way to write the line I wrote above, to add formatting to the date? Quote Link to comment https://forums.phpfreaks.com/topic/247860-date-formatting/#findComment-1272729 Share on other sites More sharing options...
Xpluration Posted September 26, 2011 Share Posted September 26, 2011 Does your date format have leading 0's for the day or month? i.e. is it always 9 for September and not 09? If the day is 5, is it 5 or 05? So for September 5th 2011 will it be 2011-9-5? or 2011-9-05? Also, what version of PHP do you have? Quote Link to comment https://forums.phpfreaks.com/topic/247860-date-formatting/#findComment-1272731 Share on other sites More sharing options...
NiallThistle Posted September 26, 2011 Author Share Posted September 26, 2011 Does your date format have leading 0's for the day or month? i.e. is it always 9 for September and not 09? If the day is 5, is it 5 or 05? So for September 5th 2011 will it be 2011-9-5? or 2011-9-05? Also, what version of PHP do you have? PHP v4 The date could be anything, but the info is taken from three drop downs (day, month and year) in a form on the previous page. Quote Link to comment https://forums.phpfreaks.com/topic/247860-date-formatting/#findComment-1272734 Share on other sites More sharing options...
jcbones Posted September 26, 2011 Share Posted September 26, 2011 $time = strtotime($_POST['date']); //get timestamp; $date = date('F d, Y',$time); echo $date; strtotime() date() Quote Link to comment https://forums.phpfreaks.com/topic/247860-date-formatting/#findComment-1272740 Share on other sites More sharing options...
NiallThistle Posted September 26, 2011 Author Share Posted September 26, 2011 That's excellent, thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/247860-date-formatting/#findComment-1272749 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.