Hi all,
I need a query that will return last thursday date dynamically. Can any one send it to me?
Thanks in advance,
1 12269
Hi,
If you are looking for the last Thursday -
-
-
-
declare @date datetime,
-
@day int
-
-
-
-
declare @startdate datetime,
-
-
@enddate datetime
-
-
--set @date = getdate()
-
-
-
-
set @day = datepart(day,getDate())-1
-
-
-
-
set @startdate = DATEADD(day,-30,getDate())
-
-
set @enddate = getdate()
-
-
-
-
SELECT TOP 1 Date
-
-
FROM
-
-
( Select dateadd(day,number,@startdate) AS Date
-
-
from master.dbo.spt_values
-
-
where master.dbo.spt_values.type='p'
-
-
AND dateadd(day,number,@startdate)<=(@enddate)
-
-
) AS T
-
-
WHERE DATENAME(dw, Date) = 'Thursday' AND
-
Date <= GetDate()
-
ORDER BY Date desc
-
If you are looking for last Thursday in a month: -
-
-
-
declare @date datetime,
-
@day int
-
-
-
-
declare @startdate datetime,
-
-
@enddate datetime
-
-
set @date = getdate()
-
-
-
-
set @day = datepart(day,@date)-1
-
-
-
-
set @startdate = DATEADD(day,-@day,@date)
-
-
set @enddate = DATEADD(month,1,@startdate)
-
-
-
-
SELECT TOP 1 Date
-
-
FROM
-
-
( Select dateadd(day,number,@startdate) AS Date
-
-
from master.dbo.spt_values
-
-
where master.dbo.spt_values.type='p'
-
-
AND dateadd(day,number,@startdate)<=(@enddate)
-
-
) AS T
-
-
WHERE DATENAME(dw, Date) = 'Thursday'
-
-
ORDER BY Date desc
-
thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dennis Marks |
last post by:
There seems to be a major program with the automatic display of the
last modified date. Using the javascript "document.lastModified"
sometimes returns the correct date and sometimes 1 Jan 1970...
|
by: yxq |
last post by:
Hello,
The XP Desktop clean wizard can get the last access time of desktop
shortcut, i found that the info come from
...
|
by: Steel |
last post by:
Hi at all
it is the first time that I use PHP and I need only to modify the last
modified date of a file
I maked a FIRST little script like this:
$FileName="myfile.txt";
$Today...
|
by: IdleBrain |
last post by:
Hello All,
Is it possible to obtain the last Modified date for the source code
from within the application?
If yes, please let me know how it is done.
|
by: MarcJoseph |
last post by:
I have a database that is shared my multiple users who enter and update
records on a weekly basis. Is there a way I can add a field to my main
data table that will automatically generate the...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I format the Last-Modified date with
javascript?...
|
by: mariyana |
last post by:
How can we get the last accessed date and the last modified date of a file using VB6
|
by: myemail.an |
last post by:
Hi all,
I am a novice to Access, and was wondering if I could get some help on
a problem I can't solve.
I have a database with customer payments, structured like this:
customer code
type of...
|
by: perhapscwk |
last post by:
How to update stored cookies value without change the cookies expired date?
when I login on monday, I have use "remember me for 1 week" to store my login in cookies with my last login...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |