954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

date = curdate

hi i have a query which should work however it returns nothing.

i have at least 2 entries where completed = No and the date of the task is today.

the code is:

SELECT count(TaskID) AS DueToday, DATE_FORMAT(`TaskDueDate`,'%d.%m.%Y') AS XLABEL FROM tasks
WHERE 'XLABEL' = CURDATE( ) AND Completed = 'No'


however it returns 0

TaskDueDate column in the database is a datetime type that is why i am using dateformat to only display the date of the column as opposed to the date and time.

thanks again

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

i have even tried changing it to this:

SELECT count(TaskID) AS DueToday, DATE_FORMAT(`TaskDueDate`,'%Y-%m-%d') AS XLABEL FROM tasks
WHERE 'XLABEL' = CURDATE( ) AND Completed = 'No'


i think it is the curdate( ) that is causing the issue however i have tried NOW() and still does not work.

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

Try changing

CURDATE()


to

date('Y-m-d')
simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

no still does not return and count of tasks due today.

anything else i can try?

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

Just realised your column to compare with today's date is formatted incorrectly, should be:

SELECT count(TaskID) AS DueToday, DATE_FORMAT(`TaskDueDate`,'%Y-%m-%d') AS XLABEL FROM tasks
WHERE `XLABEL` = date('Y-m-d') AND Completed = 'No'


You had ' ' around the XLABEL which is incorrect, is using quotes around column names they should be like ` `. Or you can just get rid of them altogether to prevent this issue in future (for instance you haven't put them around your Completed column name).

Also check that your column names are in the correct case as they are case sensitive - so is your XLABEL column actually all in caps in your database?

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

thanks for this, XLABEL is not a column in the database, TaskDueDate is the column i am using XLABEL as an alias as i need to trim TaskDueDate column from a datetime type to just the date.

i ran your query however no joy.

thanks again

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

Oh yes, I had missed that - you can't use an alias like you are. Just change the where clause to use your correct column

WHERE TaskDueDate = date('Y-m-d')
simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

yeah thanks for that, only issue is it returns 0 back where there is definately an entry.

really strange.

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

strange thing is the overdue query i have works fine

SELECT COUNT(tasks.TaskID) AS TasksDue, tasks.TaskDueDate, tasks.Completed
FROM tasks
WHERE tasks.TaskDueDate < CURRENT_DATE() and tasks.Completed = 'No'


i did try changing it to

tasks.TaskDueDate = CURRENT_DATE()

but no joy

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

Have you tried running the query in PHPMyAdmin (obviously putting in some data in place of the variables) and see what happens? It should give you an error message if it is your query that isn't working.

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

yeah i am running it on php my admin to test the queries as always prefer to make sure they work there first.

returns no error just duetoday 0

which is definately not right.

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

resolved it now with thanks to a friend:

SELECT count(`TaskID`) AS `DueToday` FROM tasks WHERE DATE_FORMAT(`TaskDueDate`,'%Y-%m-%d') = DATE_FORMAT( NOW(),'%Y-%m-%d') AND `Completed` = 'No'


thanks for your help simplypixie

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

I was just going to say - I have run and tweaked your query and got it to work. It didn't like the as FeeID and as XLABEL so I changed those to all lower case and got the result as expected (using CURDATE()).

So the code (which is a bit more simple than what you have finished with) is:

SELECT count(TaskID) as taskid, date_format(TaskDueDate, '%d.%m.%Y') as xlabel FROM tasks WHERE TaskDueDate = CURDATE() AND Completed = 'No'
simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

thanks simplypixie

mrhankey
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You