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

Author  Topic 

santana
Yak Posting Veteran

72 Posts

Posted - 2009-09-30 : 08:05:19
Hi,

I have this syntax date:

dateadd(mm,+1,dateadd(yy,-1,MonthDate))

But it shows me the all/complete date format. How can I change it for only YYYYMM format?

Example:
MonthDate = "2008-10-01 00:00:00:000"
I want: 200711

Thanks!

Regards,

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 08:07:19
quote:
Originally posted by santana

Hi,

I have this syntax date:

dateadd(mm,+1,dateadd(yy,-1,MonthDate))

But it shows me the all/complete date format. How can I change it for only YYYYMM format?

Example:
MonthDate = "2008-10-01 00:00:00:000"
I want: 200711

Thanks!

Regards,


What do you want to do with convered date?

Madhivanan

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

santana
Yak Posting Veteran

72 Posts

Posted - 2009-09-30 : 08:18:09
I have one date MonthDate = "2008-10-01 00:00:00:000", but I need the date in format YYYYMM 11 months before (200711).

Thank you!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 08:20:18
quote:
Originally posted by santana

I have one date MonthDate = "2008-10-01 00:00:00:000", but I need the date in format YYYYMM 11 months before (200711).

Thank you!



select convert(char(6),dateadd(month,-11,getdate()),112)

But you have not answered to my question

Madhivanan

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

santana
Yak Posting Veteran

72 Posts

Posted - 2009-09-30 : 08:24:04
Sorry, I dont understand your question!

I want to use only the last 11 months, and I need to filter in my query.

I can change the getdate() to my field MonthDate?

thank you!
:-)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 08:31:16
quote:
Originally posted by santana

Sorry, I dont understand your question!

I want to use only the last 11 months, and I need to filter in my query.

I can change the getdate() to my field MonthDate?

thank you!
:-)


So, you want to get data for the last 11 months only?
You can use MonthDate in place of getdate()

Madhivanan

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

santana
Yak Posting Veteran

72 Posts

Posted - 2009-09-30 : 10:24:51
It is working. Thank you a lot! Regards,
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-30 : 10:31:58
quote:
Originally posted by santana

It is working. Thank you a lot! Regards,


You are welcome

Madhivanan

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

- Advertisement -