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
 General SQL Server Forums
 New to SQL Server Programming
 IF Date Query

Author  Topic 

Bryan Malone
Starting Member

2 Posts

Posted - 2014-11-12 : 23:00:56
Greetings, I am very new to forums and very new to SQL programming. The more basic the code, the better.
I would like to return a Julian Date MMMYY based on 7AM being the 'new day'.

Ex.
1/1/2014 @ 7AM = 00114
1/1/2014 @ 11PM = 00114
1/2/2014 @ 6AM = 00114
1/2/2014 @ 7AM = 00214

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-11-12 : 23:14:07
[code]declare @dates table
(
[date] datetime
)

insert into @dates ([date]) select '2014-01-01 07:00'
insert into @dates ([date]) select '2014-01-01 23:00'
insert into @dates ([date]) select '2014-02-01 06:00'
insert into @dates ([date]) select '2014-02-01 07:00'

select [date],
mth = month(dateadd(hour, -7, [date])),
yr = year(dateadd(hour, -7, [date])),
julian = right('000' + convert(varchar(10), month(dateadd(hour, -7, [date]))), 3)
+ right(convert(varchar(10), year(dateadd(hour, -7, [date]))), 2)
from @dates
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Bryan Malone
Starting Member

2 Posts

Posted - 2014-11-12 : 23:35:52
Sorry for the confusion. I need the code to read the current date/time and display only the Julian Date.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-11-13 : 06:27:02
[code]SELECT julian = right('000' + convert(varchar(10), month(dateadd(hour, -7, getdate()))), 3)
+ right(convert(varchar(10), year(dateadd(hour, -7, getdate()))), 2)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -