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

SQL Trigger 1

Status
Not open for further replies.

Gaylord

Technical User
Sep 26, 2002
49
0
0
DE
Hi,

I am trying to write a trigger, whereby it gets todays date, which is pretty easy, but I also want the date of the monday of that week...

So if I inserted some thing tomorrow I want the date in the date column as 6/12/04, and a weekstarted column with 5/12/04... I have no idea how to go about this, as I am a trigger virgin!

Hope someone can help.

Jamie
 
Can't help you with triggers but if you want the monday of the week a given date is in, and you consider week being from Monday to Sunday, you get it as sql statement
DATEADD(dd,-(7+DATEDIFF(dd,0,getdate())%7)%7,getdate())
replacing the two getdate():s with your given date.

Cheers


[blue]Backup system is as good as the latest recovery[/blue]
 
Yksvaan,

Excellent, thank you so much for that! Have squeezed it into my trigger and works perfectly.

Regards

Jamie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top