Jump to content

Str To Date Not Working


Alicia

Recommended Posts

Hi guys,

 

can somebody give me an idea why this query doesn't work? thanks

 

SELECT SUM(credit) AS usage,  STR_TO_DATE(`created`, '%m/%d/%y'),STR_TO_DATE(`expiry`, '%m/%d/%y') FROM `suax` WHERE  STR_TO_DATE(`created`, '%m/%d/%y') >= '11/5/2012' AND STR_TO_DATE(`expiry`, '%m/%d/%y') = '11/15/2012' LIMIT 0 , 30

 

my created and expiry format is a string like this 1/15/2012 04:05:22

 

 

Please advise.thanks

Link to comment
https://forums.phpfreaks.com/topic/270710-str-to-date-not-working/
Share on other sites

So many errors!

 

You are not correctly defining the current format to be converted (see Jessica's reply)

You are converting to mysql date format yet comparing against your string format (use >= 'yyyy-mm-dd' etc)

You logic is screwed - you look for those greater than one date AND equal to another (only ever returning the latter)

You need column aliases for your converted dates

 

EDIT:

The time element will be ignored

mysql> select STR_TO_DATE('22/01/2012 09:30:00','%d/%m/%Y') as dob;
+------------+
| dob	 |
+------------+
| 2012-01-22 |
+------------+

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.