Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple date question

Status
Not open for further replies.

jararaca

Programmer
Jun 1, 2005
159
0
0
US
Hi--

I need to update all rows in a table that have a date in a datetime field that comes after a certain date. I'm not sure how to write that.

...
WHERE DateTimeColumn >= '9/1/2005'

I must need to convert the string value at the end of this WHERE clause to an actual datetime? Can someone please give me an example of how to do this?

Thank you.
 
You got it. But it can be better. Some dates are in the format Month/Day/Year and others can be Day/Month/Year. Since this can me ambiguous, it's best to use Year-Month-Day.

Also, it's usually best to select the data. Then, only after you're sure that the records are correct.

For Example...

Select *
From Table
Where DateTimeColumn >= '2005-09-01'

If this is correct (based on the where clause), then change it to an update (or a delete depending on your situation).

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
conversion is not necessary, sql server does recognize date strings

however, if you want to avoid ambiguity problems (is it jan 9th or sept 1st??) it's better to write your date strings in yyyy-mm-dd format

WHERE DateTimeColumn >= '2005-09-01' /* sept 1 */

r937.com | rudy.ca
 
It must be reassuring to the original poster when there are several 'nearly identical' responses. [wink]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top