views:

222

answers:

2

I have a DateTime field in SQL Server for some products expiration (ExpirationDate). I need to increment all the items manually, and set their expiration a month later than the date stored in the field currently. How can I do that?

+9  A: 

I don't have SQL Server on my computer, so I cannot test, but what about using DATEADD, a bit like this :

update your_table set your_field = DATEADD(month, 1, your_field)
Pascal MARTIN
I'm pretty sure you mean to say update your_table, fixed it for you.
RedFilter
@OrbMan : ergh, yes, of course :-( Thanks for the edit !
Pascal MARTIN
Thanks guys, really helpful! I appreciate it.
Cristi Cotovan
+9  A: 
UPDATE Products SET ExpirationDate=DATEADD(month,1,ExpirationDate) WHERE Type='Cheese'
Jonas Elfström
+1 for implying cheese never expires...
Remus Rusanu
Exactly, it only gets cheesier.
Jonas Elfström