Jump to content

format date inside query


tagteamcomputing
Go to solution Solved by Barand,

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

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.