Jump to content

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

One problem I see is that 1/15/2012 04:05:22 is NOT '%m/%d/%y'. 1/15/2012 would be %m/%d/%y. I've NEVER used that function so I don't know if that it is.

 

However, you got a syntax error, and you didn't post it...why exactly? 

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 |
+------------+

Edited by Barand
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.