Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Calculating Today in Days

Author  Topic 

melon
Starting Member

4 Posts

Posted - 2004-11-08 : 03:14:59
I am facing problems in getting amount of days for GetDate().
Anyone out there has any idea?

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-11-08 : 03:36:00
What result are You expecting ?

rockmoose
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-08 : 04:16:30
are you trying to get the day part of getdate?
datepart(day,getdate())
or getting the number of days difference?
datediff(day,getdate(),dateValue)

--------------------
keeping it simple...
Go to Top of Page

melon
Starting Member

4 Posts

Posted - 2004-11-08 : 04:17:59
i'm expecting 218 days (11/8/2004)in year 2004 (365 days)
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-08 : 04:28:14
quote:
Originally posted by melon

i'm expecting 218 days (11/8/2004)in year 2004 (365 days)




datediff(day,'1/1/2004',getdate()), but i got 312?


--------------------
keeping it simple...
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-11-08 : 04:42:37
Yeah 218 is wrong, 312 is wrong, I vote 223

set dateformat dmy
declare @d datetime
set @d = '11/8/2004'

select datediff(d,cast(datename(year,@d)+'0101' as datetime),@d)

select dateadd(d,223,'20040101')


rockmoose
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-08 : 05:06:20
actually, you have august 11, 2004 rockmoose, not nov. 8, 2004

--------------------
keeping it simple...
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-08 : 05:08:49
quote:

doing it manually, got 316, hmm... also total days in 2004 is 366 not 365, weird,anyways, someone here might explain why.



rockmoose was gentleman to point out 316, typo here on the spreadsheet (gotta double check replies before posting , it's 312.

--------------------
keeping it simple...
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-11-08 : 05:13:53
quote:
Originally posted by jen

actually, you have august 11, 2004 rockmoose, not nov. 8, 2004

--------------------
keeping it simple...



That was my intention as well, figured that melon's date was
d/m/y since he wanted 218 days.
Of course if we do m/d/y we get 312 as you posted Jen

I guess the spec was not so good melon

rockmoose
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2004-11-08 : 05:32:52
Of course, if you want a zero-based day-of-year number rather than the number of days since the start of a given year, DATEPART(dy, @d)-1 would be more useful.
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-11-08 : 06:13:51

Bang head on desk, Read BOL 10x, and go to bed early...

rockmoose
Go to Top of Page

melon
Starting Member

4 Posts

Posted - 2004-11-11 : 20:17:34
Sorry for this late reply as i was too busy solving other problems i faced...

Hooray.... thank you so much guys....

Go to Top of Page

melon
Starting Member

4 Posts

Posted - 2004-11-11 : 20:49:52
again i'm sorry...

can anyone please tell me how to get total days for the year?

whether it's 365 or 366 ???
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-11 : 21:05:20
quote:
Originally posted by melon

again i'm sorry...

can anyone please tell me how to get total days for the year?

whether it's 365 or 366 ???



same syntax, datediff...

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -