473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Find the first Day (01) and the Last Day (28) for a specified month in SQL Function?

4
I need to write an SQL Function (UDF) to find the First Day (int) and the Last Day (int) when I specify a date.

For example: When I specify (20130217) (i.e. Feb 17th, 2013), I should be able to find the First Day (01) and the Last Day (28) for the specified month (in this case, Feb).

How can I do that? Please provide the necessary code to implement this feature in my SQL Function.

Thanks.
Mar 4 '13 #1

✓ answered by ck9663

I think he's just asking for a straight forward function to get the first and last day of the month.


Here, find your dates here.

Happy Coding!!!


~~ CK

3 1429
Rabbit
12,516 Expert Mod 8TB
This is not a code writing service but if you post the code you've tried along with a description of the problem you're having with the code, we can help guide you to a solution.

As a hint, you can use the various date functions combined with cast functions to build the dates you need.
Mar 4 '13 #2
ck9663
2,878 Expert 2GB
I think he's just asking for a straight forward function to get the first and last day of the month.


Here, find your dates here.

Happy Coding!!!


~~ CK
Mar 4 '13 #3
Expand|Select|Wrap|Line Numbers
  1. DECLARE @yourDate DATETIME
  2. SET @yourDate = '2013-02-17'
  3.  
  4. SELECT DAY(DATEADD(MONTH, DATEDIFF(MONTH, 0, @yourDate), 0)) AS First,
  5.        DAY(DATEADD(MONTH, DATEDIFF(MONTH, -1, @yourDate), -1)) AS Last
Dec 9 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sebastian | last post by:
I have a query that runs perfectly when doing a date equal comparison (see last line in the subquery: AND T2.DQ_DAT = '14.02.2005'). A direct comparison of the date is not sufficient for my...
3
by: Gol Yass | last post by:
Dear Newsgroup, Is there a function in Access XP to take a date or month , and return the last day in that month? Ex: the last day in september is 30 or the last day in May is 31 . Thank...
7
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date....
5
by: hunt4grouse | last post by:
I'm looking for C code that will give me the last day of the month. Input - any day that I pass in as a variable.... input = 20050201 Output - calculate and format with slashes.... output =...
2
by: Sasidhar Parvatham | last post by:
Hello All, Is there a way I can get dates for first and last fridays of a month? Any suggestion would be helpful. Thanks.
1
by: John Rugo | last post by:
Hi All, Can someone help me figure out how to find the number of weeks within a specified month? Thanks.
2
by: Christos via AccessMonster.com | last post by:
Dear friends I would like to find the first and the last element of a record in a table. Is there any possibility especially if yoy have not promary key? Christos -- Message posted via...
2
by: Alex | last post by:
Hello all, I'm at a loss on how to do this. We're using MS SQL 2000 Server and I have a list of fields I need to find the first and last entry for. Here's an example of the table: Number -...
5
jenkinsloveschicken
by: jenkinsloveschicken | last post by:
Could someone please take a look at my query and tell me what I am missing? The strange thing is that when I first built the query, it was working fine. Then it broke. I suspect the problem is the...
3
by: paulvonhippel | last post by:
I'd like to count the number of transactions for each debit card and month over a 3-month period. But this query -- select DBT_CRD_DIM_NB, month (tran_dt) as tran_mnth, count(*) as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.