Jump to content

Need Date Comparison and delete record query


alan93

Recommended Posts

I would change the field to a 'date' data type rather than varchar(16).  Try this code out:

 

select * from table_name WHERE date_column <= CURDATE()

or

select * from table WHERE date_column >= CURDATE() 

 

In your case you would use Delete but try the Select first to make sure that it returns the records you need.

Link to comment
Share on other sites

I have a date field in records that is formatted as such:

 

1/1/2009

 

or

 

4/5/2007

 

This field that holds these values is a varchar(16)

 

I need to delete all records that has a date older than todays date.

How do I do that?

 

Good luck doing it with VARCHAR. Shoudla done with a date type column.

Link to comment
Share on other sites

If I were you I would create a new field with date_time datatype and write a script to go through your current varchar dates and convert them...  It will make things easier for this situation and future problems.

Link to comment
Share on other sites

I didn't know you could change the type after the column was populated. I guess I could try that.

Hope it doesn't break anything.

 

[

quote author=ainoy31 link=topic=220469.msg1011351#msg1011351 date=1223666580]

I would change the field to a 'date' data type rather than varchar(16).  Try this code out:

 

select * from table_name WHERE date_column <= CURDATE()

or

select * from table WHERE date_column >= CURDATE() 

 

In your case you would use Delete but try the Select first to make sure that it returns the records you need.

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.