Jump to content

Recommended Posts

Hi Guys

 

I am trying to get all records that are less than the current date. See code below followed by problem:

 

CREATE TABLE courses (
course_id integer auto_increment NOT NULL,
course_finish_date varchar(10),
PRIMARY KEY(course_id)
);
SELECT * FROM courses WHERE course_finish_date < CURDATE();

 

The SELECT statement works but it doesnt return any results (when it should). I suspect the reason for this is because course_finish_date is a varchar and not a date/timestamp. The column stores the date in the following format: DD/MM/YYYY - Is there any way I can convert it to a date and THEN compare ?

Link to comment
https://forums.phpfreaks.com/topic/183036-comparing-dates/
Share on other sites

Thanks. I couldnt use the STR_TO_DATE() but I managed to use strtotime() to convert the date in a 10 digit date number. Now, I need to compare that date number will the current date to workout the difference between the two. I tried DATEDIFF(course_finish_date, CURDATE()) < 0 - Namely all dates that come BEFORE today, but it returns no results when it should. Any ideas where Im going wrong ?

Link to comment
https://forums.phpfreaks.com/topic/183036-comparing-dates/#findComment-966136
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.