0

I need a way to make the datetime format looks like this : " 2013-10-23T12:30 "

I did it this way but it's not working:

 echo "<input name='showdatetime' type='datetime-local' id='showdatetime' value='" . date( "Y-m-dAh:i" , $show->datetime ) . "'><br/>";

Thank you

ouzoumzak
  • 95
  • 1
  • 7
  • no output...the datetime input is empty...this is why i need to make my datetime in this format "2013-10-23T12:30" so the datetime shows, by default, in the input – ouzoumzak Apr 29 '13 at 20:23
  • If the output is empty then `$show->datetime` is probably blank. Have you verified it has a value? What value does it have? – John Conde Apr 29 '13 at 20:24
  • the value shown is "1970-01-01AM01:33" but its not true date...i dnt know why – ouzoumzak Apr 29 '13 at 20:26
  • That's probably because `$show->datetime` is not a unix timestamp – John Conde Apr 29 '13 at 20:26
  • Why don't you try with [`DateTime::format`](http://php.net/manual/en/datetime.format.php)? – fgb Apr 29 '13 at 20:28
  • well, my main idea is that i have a page for an admin to edit shows for movie in theaters...i need the admin, when editing a show, to see the datetime...so i need a way to make the datetime in database to looks like "2013-10-23T12:30" so it will be shown in the input and admin can edit it – ouzoumzak Apr 29 '13 at 20:28
  • That is ISO8601 formatting. And it's been asked a few times already. See [here](http://stackoverflow.com/q/903203/634824) and [here](http://stackoverflow.com/q/7367953/634824) – Matt Johnson-Pint Apr 29 '13 at 20:29
  • what's the value of `$show->datetime`? – MarioP Apr 29 '13 at 20:31
  • @MattJohnson im very newbie in it...and i didnt rly understand what should i do...can u help more plz – ouzoumzak Apr 29 '13 at 20:40
  • Does date( "Y-m-dAh:i" , strtotime($show->datetime) ) help? – Andrey Volk Apr 29 '13 at 20:45
  • So, you told us the date shown is 1970-01-01AM01:33. Is that a correct format? Is that a correct date? What is your issue?The date or the format. If your problem is the date, you need to provide us with more information. Because the property $show->datetime seems do not have a valid date to be formatted. The code I wrote in my answer is showing the current date in the input. – Jose Areas Apr 29 '13 at 20:47
  • this is the datetime in database :2013-04-02 02:00:00 and this is the code echo "show datetime :"; echo "
    "; now if i put in the value field like this format "2013-10-23T12:30" it will be showed in input field correctly so my idea is to convert the datetime to smth like this for the correct datetime 2013-04-02T02:00
    – ouzoumzak Apr 29 '13 at 20:54

2 Answers2

0

Try this:

$date = getdate();

echo "<input name='showdatetime' type='datetime-local' id='showdatetime' value='" . date( "Y-m-d h:i A",$date[0] ) . "'><br/>";
Jose Areas
  • 719
  • 3
  • 11
0

You can use \ to escape characters, like the T. So you want the following format:

date('Y-m-d\TH:i')

See Example 2 in the PHP date documentation

Phill Sparks
  • 20,000
  • 3
  • 33
  • 46