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
 Date Function

Author  Topic 

diggydee
Starting Member

5 Posts

Posted - 2009-10-13 : 10:40:29

Hi Guys,

I need you help, I have date field in my table, Its in Year Month format like 200910, i am using yearmonth in where class
like this

where yearmonth=200910

now they going to do automated, so i have to write date function which returns current year and month data every times it runs

Can any one please help me in this

Thanks
Diggy

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-13 : 10:54:45
[code]where yearmonth = convert(int, convert(varchar(6), getdate(), 112))[/code]

or

[code]
where yearmonth = year(getdate()) * 100 + month(getdate())
[/code]


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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-13 : 10:54:58

where cast(cast(yearmonth*100+01 as varchar(8))) as datetime)>=dateadd(month,datediff(month,0,getdate()),0) and cast(cast(yearmonth*100+01 as varchar(8))) as datetime)<dateadd(month,datediff(month,0,getdate())+1,0)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-13 : 11:00:01
Tan's is simpler

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

winterh
Posting Yak Master

127 Posts

Posted - 2009-10-13 : 11:20:39
quote:
Originally posted by madhivanan

Tan's is simpler

Madhivanan

Failing to plan is Planning to fail



yes, yes it is.

[/fail at query]
Go to Top of Page
   

- Advertisement -