0

I have one doubt. I have in mySQL database a date with the format "NOW()": 2013-01-28 12:53:26 where I create a ticket. So, I want to get this data and convert to this: date("YmdHis"), using a query.

I've tried to do something like this, using a variable on echo:

$get_data = $rsres->Fields('create_time'); 
echo gmdate("YmdHis",$get_data);

However without sucess. What's the problem?

Thanks.

pedroF
  • 11
  • 3

4 Answers4

4

Use date() and strtotime()

echo date("YmdHis", strtotime($get_data));
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Take care to provide a truly compatible string in $get_data. `strtotime` is great but not an oracle ;) – ToBe Feb 07 '14 at 14:00
  • They already mention their dates are stored in a compatible format so they should be fine – John Conde Feb 07 '14 at 14:01
  • Works but gets the actual data, not the data that I want, when created the ticket in this case – pedroF Feb 07 '14 at 14:10
  • You're going to have to explain yourself better than that. How is it not the data you want? – John Conde Feb 07 '14 at 14:11
  • This echo really works. But I want to retrieve the data when the ticket was created. Imagine, I create now a ticket with date NOW(). And After some time imagine, I want to see the XML file, and should appear the data when created! Create time: 2014-02-07 14.15.00 Data to get ($get_data): 20140207141500 – pedroF Feb 07 '14 at 14:16
  • The echo is just to show you how to use it. That small snippet still works without the echo. Just put it where you need it and save the output in a variable. – John Conde Feb 07 '14 at 14:17
  • Ok I think that's fine! – pedroF Feb 07 '14 at 14:18
1

gmdate() expects a UNIX timestamp. Your sql data is not in that format. You first have to convert it to such using for example strtotime

Tularis
  • 1,506
  • 1
  • 8
  • 17
0

Why don't you modify your query? Check this:

SELECT FORMAT(column_name,format) FROM table_name;

Let me know if useful.

Joaquín O
  • 1,431
  • 1
  • 9
  • 16
0

You can use this to convert your Date

echo date("YmdHis", strtotime($myDate)); 
kasoft
  • 456
  • 6
  • 19
  • Works but gets the actual data, not the data that I want, when created the ticket in this case. – pedroF Feb 07 '14 at 14:02