Jump to content

[SOLVED] Changing Date format while returning data?


Gnub

Recommended Posts

Is there a way to change the format of a Date during a query?

 

Example.

 

The Date is in American Format MM/DD/YYYY

 

When im returning the data, i want the date in Euro Format, DD/MM/YYYY

 

Is there a way to do this during the main query(when asking for specific info) or will i be better off finding a way of doing it somewhere on my php script?

Link to comment
Share on other sites

I've had a bash with this function, but it's not liking my attempts.

 

$sql = "Select * FROM `Teletext` WHERE DepartureDate BETWEEN '$DateFrom' AND '$DateTo' Order BY Price ASC;"

 

Got an idea where i can add that function?

 

Tried before @DepartureDate@ and before @ORDER BY@ .

Link to comment
Share on other sites

Round 3...

 

Had yet another bash at this function, this is the query, however the date does not change when i check the results.  it remains YYYY-MM-DD, when i want it at DD-MM-YYYY.

 

Any help would be great. :)

 

SELECT `Teletext`.*,DATE_FORMAT(`DepartureDate`, '%d %m %Y') AS revised_date, WHERE DepartureDate BETWEEN '$DateFrom' AND '$DateTo' Order BY Price ASC;

 

Should i be using the `DepartureDate` when echo'ing the results?  im completely new at this revised date, and not using the (*) wild card.

 

cheers in Adv.

Link to comment
Share on other sites

No you need to use the new column it is now referenced as when you echo the results, so it will be revised_date you need to use. By echoing DepartureDate you are getting the original value before you applied the formatting.

 

As thorpe has said, you really need to type in the names of the fields you require and not use *, so as an example it would be

 

   SELECT col1, col12, col3 FROM table1 WHERE col1 BETWEEN '$here' AND '$there' ORDER BY col1 desc;

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.