SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 exact date
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  03:29:50  Show Profile  Reply with Quote
I think this simple. First I would like to know how to get the exact date (today's date)?

SwePeso
Patron Saint of Lost Yaks

Sweden
30111 Posts

Posted - 05/08/2008 :  03:30:56  Show Profile  Visit SwePeso's Homepage  Reply with Quote
GETDATE()



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  03:33:55  Show Profile  Reply with Quote
ok what i want to get the date every 2 weeks. Meaning, it will change after 2 weeks.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30111 Posts

Posted - 05/08/2008 :  03:55:29  Show Profile  Visit SwePeso's Homepage  Reply with Quote
And meanwhile, which date would you like to return?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

United Kingdom
3608 Posts

Posted - 05/08/2008 :  03:57:05  Show Profile  Reply with Quote
So run getdate() every 2 weeks.
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  03:58:37  Show Profile  Reply with Quote
yes, preferably Sundays. Like I want to make it stay as May 4 and t will changed after 2nd sunday which is May 18.
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

United Kingdom
3608 Posts

Posted - 05/08/2008 :  03:59:18  Show Profile  Reply with Quote
How is that an exact date?

Also, what time on that date do you want it to be?

Edited by - RickD on 05/08/2008 04:01:08
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  04:02:07  Show Profile  Reply with Quote
I have a report and it's being dated every other sundays. Instead of manually entering the date, I want to make it automatic. Like it will change every other week.
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

United Kingdom
3608 Posts

Posted - 05/08/2008 :  04:08:13  Show Profile  Reply with Quote
Well, this will get you the previous Sunday:

select dateadd(day, 1 - datepart(dw, getdate()), getdate())

But you best bet would be to store the date in a table each 2nd Sunday and then use this in your query.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30111 Posts

Posted - 05/08/2008 :  04:09:23  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT DATEADD(DAY, DATEDIFF(DAY, '19000108', GETDATE()) / 14 * 14, '19000107')



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  04:13:10  Show Profile  Reply with Quote
ok so this will changed automatically comes may 18? or does it change every day?
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

United Kingdom
3608 Posts

Posted - 05/08/2008 :  04:14:10  Show Profile  Reply with Quote
quote:
Originally posted by Peso

SELECT DATEADD(DAY, DATEDIFF(DAY, '19000108', GETDATE()) / 14 * 14, '19000107')



E 12°55'05.25"
N 56°04'39.16"



Nice.
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  04:17:56  Show Profile  Reply with Quote
okay i think it work. How about for dates April 20, April 6 and March 23. I would like them to aumatically moved every other sundays. Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30111 Posts

Posted - 05/08/2008 :  04:20:30  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Try for yourself. How hard is that to do?


E 12°55'05.25"
N 56°04'39.16"

Edited by - SwePeso on 05/08/2008 04:20:52
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30111 Posts

Posted - 05/08/2008 :  04:22:25  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Oh my God!
My suggestion returned

March 23 for the input date April 6.
April 6 for the input date April 20.
April 20 for the input date April 23.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  04:23:48  Show Profile  Reply with Quote
not really sure how. Please just last one. Thanks
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

United Kingdom
3608 Posts

Posted - 05/08/2008 :  04:25:53  Show Profile  Reply with Quote
It also returns the May 4 when May 18 is input.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30111 Posts

Posted - 05/08/2008 :  04:28:18  Show Profile  Visit SwePeso's Homepage  Reply with Quote
It is a bounding thingy. OP never stated which date to return when input date is a sunday.
If you want current sunday to be returned (if a every second sunday), replace '19000108' with '19000107'

SELECT DATEADD(DAY, DATEDIFF(DAY, '19000107', GETDATE()) / 14 * 14, '19000107')



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  04:28:41  Show Profile  Reply with Quote
Yes but it will be changed on May 19.
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 05/08/2008 :  04:40:56  Show Profile  Reply with Quote
anyone can help?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30111 Posts

Posted - 05/08/2008 :  04:47:14  Show Profile  Visit SwePeso's Homepage  Reply with Quote
quote:
Originally posted by cutiebo2t

anyone can help?
So you don't appreciate the help and suggestion I have given for free the last hour?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000