Jump to content

format date inside query


tagteamcomputing

Recommended Posts

I am trying to format the date from a timestamp to m/d/Y inside the query.

 

What I am trying ends up returning a blank result for the date

stmt = $conn->prepare("SELECT orderid, DATE_FORMAT(date, '%m/%d/%Y') as orderdate, email, b_state, s_country, subtotal FROM xcart_orders where date BETWEEN $BeginDate AND $EndDate ");
 

I am a newbie to php and even more so to php 7 and PDO so i apologize if this is a simple one.

Link to comment
Share on other sites

I assume when you say "timestamp" you are referring to a unix timestamp (integer) and not a mysql timestamp (yyyy-mm-dd hh:ii:ss).

 

In which casa you need to first convert to mysql datetime format before you can use date_format(). Store date/time info in a database using DATE, DATETIME or TIMESTAMP type columns, not integer. They are readable and wor with the functions.

,,, DATE_FORMAT(FROM_UNIXTIME(date), '%m/%d/%Y') as orderdate
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.