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
 Transact-SQL (2000)
 Getting current month name

Author  Topic 

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-02-12 : 13:23:33
Hi Everybody

I am trying to get some function which returns

- current month name
- current year
- date range ( for February displaying 2/1/2007 - 2/28/2007)
-year range ( 1 Jan 2007 - 31 Dec 2007)

I was wondering, is there any functions for these?
I searched a lot, but couldnt find a solution

It will be really greatful if someone can help me in this.

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-12 : 13:31:01
1) select datename(month, getdate())
2) select datepart(year, getdate())


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-12 : 13:36:22
3) select convert(varchar, dateadd(month, datediff(month, 0, getdate()), 0), 101) + ' - ' + convert(varchar, dateadd(month, 1 + datediff(month, 0, getdate()), -1), 101)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-12 : 13:37:57
4) select convert(varchar, dateadd(year, datediff(year, 0, getdate()), 0), 106) + ' - ' + convert(varchar, dateadd(year, 1 + datediff(year, 0, getdate()), -1), 106)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-02-12 : 13:45:47
This is a great help.
But sorry to say this that, can you please tel me how can i use this as a function so that i can set a label text to these select statements results
eg. lblDate = ?
Do i need to make any user defined functions or stored procedures with these select stmt?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-12 : 14:10:48
No, you must use the FORMAT function and NOW function if formatting the text in front-end application.
Why do you fool us and make us think you want help with T-SQL, when you really want help with VB/ASP formatting?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-02-12 : 14:16:21
I am really sorry for this.
I actually thought that as it is a function, I will ask in T-SQL
I didnt really mean to confuse you
Sorry for this
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-12 : 14:24:57
It is faster to do in front-end application.

1) FORMAT(Now, "mmm")
2) FORMAT(Now, "yyyy")


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-02-12 : 15:02:20
Thanks
Sorry once again
Will be conscious before posting
Go to Top of Page
   

- Advertisement -