Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Displaying date through sql query?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ravi - 19 Apr 2008 08:28 GMT
hi friends,
can we display last ten dates from current system date using sql
query.
example todays date
19/4/2008 from this last 10 days
18/4/2008
17/4/2008
16/4/2008
'
'
'
9/4/2008
is this possible.
i dont have any table that give me dates.
i am working on SQl server.
ThatsIT.net.au - 19 Apr 2008 17:51 GMT
Not sure what you want to do

if you have these dates in a table then its

SELECT TOP 10 mydatefield FROM mytable

if you dont then

       Dim dateArr(9)
       For i = 0 To -9 Step -1
           dateArr(Math.Abs(i)) = DateAdd(DateInterval.Day, i,
DateAndTime.Now)
           Response.Write(DateAdd(DateInterval.Day, i, DateAndTime.Now))
           Response.Write("<br>")
       Next

> hi friends,
> can we display last ten dates from current system date using sql
[quoted text clipped - 11 lines]
> i dont have any table that give me dates.
> i am working on SQl server.
Mark Rae [MVP] - 19 Apr 2008 18:21 GMT
> Can we display last ten dates from current system date using an SQL
> query?
> Is this possible?
> I don't have any table that give me dates.
> I am working on SQL Server.

There are loads of ways you could do this.

The following isn't particular robust or efficient, but it should be enough
to get you started:

CREATE TABLE #tmpDates
(
   dtmDate smalldatetime
)
DECLARE @i tinyint
SET @i = 0
WHILE @i < 11
BEGIN
   INSERT #tmpDates VALUES(DATEADD(day, @i * -1, getdate()))
   SET @i = @i + 1
END
SELECT * FROM #tmpDates ORDER BY dtmDate DESC
DROP TABLE #tmpDates

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

bruce barker - 20 Apr 2008 06:19 GMT
simple query:

  with foo (d , level)
  as
  (
    select getdate(),1
    union all
    select dateadd(day,-level,d), level + 1
    from foo
    where level < 10
  )
  select d
  from foo

-- bruce (sqlwork.com)

> hi friends,
> can we display last ten dates from current system date using sql
[quoted text clipped - 11 lines]
> i dont have any table that give me dates.
> i am working on SQl server.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.