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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Current Date

Status
Not open for further replies.

quinnipiac0807

Programmer
Oct 25, 2004
38
US
I'm trying to put the current date into a table with column name StopDate (smalldatetime) and table name psd_AssetCustoian. AssCustID is the Primary Key.

This doesn't work. Any clue why?

SET StopDate = CAST(GETDATE() AS smalldatetime) WHERE AssCustID = @AssCustID

Thanks in advance
 
The update psd_AssetCustoian part seems to be missing.

Questions about posting. See faq183-874
 
You should be doing an UPDATE. And there is a question of whether or not you want the time-of-day stored with the date.
Code:
[Blue]UPDATE[/Blue] YourTable
   [Blue]SET[/Blue] StopDate[Gray]=[/Gray][Fuchsia]DateAdd[/Fuchsia][Gray]([/Gray]dd[Gray],[/Gray][Fuchsia]DateDiff[/Fuchsia][Gray]([/Gray]dd[Gray],[/Gray]0[Gray],[/Gray][Fuchsia]GetDate[/Fuchsia][Gray]([/Gray][Gray])[/Gray][Gray])[/Gray][Gray],[/Gray]0[Gray])[/Gray]
   [Blue]WHERE[/Blue] AssCustID [Gray]=[/Gray] @AssCustID
or
Code:
   [Blue]SET[/Blue] StopDate[Gray]=[/Gray][Fuchsia]GetDate[/Fuchsia][Gray]([/Gray][Gray])[/Gray]
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
You just forgot the UPDATE <tableName> in the beginning

UPDATE psd_AssetCustoian SET StopDate = GETDate()
WHERE AssCustID = @AssCustID

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top