September 18, 2016 at 5:59 am
Comments posted to this topic are about the item T-SQL: EOMONTH
September 19, 2016 at 2:04 am
I couldn't see any of the answers that matched what I believed I should be getting - then I played around a little.
Where dates are concerned it is probably helpful to specify the date format in use, as this site has people from all over - and they might not be using the same date format as yourself.
That aside, a nice question.
September 19, 2016 at 2:05 am
Great question. Never even realized EOMONTH had an optional second parameter. Good to know.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
September 19, 2016 at 6:44 am
Practical for use is that the second parameter may have also a negative value,
thanks for this seemingly simple question Nagaraj.
September 19, 2016 at 7:05 am
Wish this was available in 2008.
September 19, 2016 at 7:31 am
:hehe: Cool - a new tool to get rid of all of my 2005 code...
September 19, 2016 at 7:54 am
BrainDonor (9/19/2016)
I couldn't see any of the answers that matched what I believed I should be getting - then I played around a little.Where dates are concerned it is probably helpful to specify the date format in use, as this site has people from all over - and they might not be using the same date format as yourself.
That aside, a nice question.
With SQL Server, dates formatted as YYYY-XX-YY will always be YYYY-MM-DD,
YYYY-DD-MM is not a valid format with SQL Server.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
September 19, 2016 at 8:01 am
George Vobr (9/19/2016)
Practical for use is that the second parameter may have also a negative value,thanks for this seemingly simple question Nagaraj.
Was going to post this. For example, one way to compensate for the still-absent BOMONTH():
SELECT DATEADD (DAY,1,EOMONTH (GETDATE,-1))
September 19, 2016 at 8:11 am
Thanks - interesting question.
- webrunner
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html
September 19, 2016 at 8:51 am
Koen Verbeeck (9/19/2016)
Great question. Never even realized EOMONTH had an optional second parameter. Good to know.
+1
Thanks, Nagaraju!
September 19, 2016 at 8:54 am
Alvin Ramard (9/19/2016)
BrainDonor (9/19/2016)
I couldn't see any of the answers that matched what I believed I should be getting - then I played around a little.Where dates are concerned it is probably helpful to specify the date format in use, as this site has people from all over - and they might not be using the same date format as yourself.
That aside, a nice question.
With SQL Server, dates formatted as YYYY-XX-YY will always be YYYY-MM-DD,
YYYY-DD-MM is not a valid format with SQL Server.
Date formatting isn't a strong point with me, so could you possibly explain this:
I only get a match within the answers listed if I swap the day and month.
I'm completely prepared to believe it is something stupid at this end.
September 19, 2016 at 9:20 am
BrainDonor (9/19/2016)
Alvin Ramard (9/19/2016)
BrainDonor (9/19/2016)
I couldn't see any of the answers that matched what I believed I should be getting - then I played around a little.Where dates are concerned it is probably helpful to specify the date format in use, as this site has people from all over - and they might not be using the same date format as yourself.
That aside, a nice question.
With SQL Server, dates formatted as YYYY-XX-YY will always be YYYY-MM-DD,
YYYY-DD-MM is not a valid format with SQL Server.
Date formatting isn't a strong point with me, so could you possibly explain this:
I only get a match within the answers listed if I swap the day and month.
I'm completely prepared to believe it is something stupid at this end.
On my local SQL 2014 machine,
DECLARE @Date Datetime = '2012-02-01' -- Feb 1, 2012
SELECT EOMONTH(@Date, 2)
GO
returns: 2012-04-30, i.e. End of month for 2 months after Feb 1, 2012
DECLARE @Date Datetime = '2012-01-02' -- Jan 2, 2012
SELECT EOMONTH(@Date, 2)
GO
returns: 2012-03-31, i.e. End of month for 2 months after Jan 2, 2012
This is what I expected. It looks like your result #2 should go with query #1 and result #1 with query #2.
If you don't believe YYYY-XX-YY cannot be YYYY-DD-MM, try same queries for dates: 2012-01-13 and 2012-13-01. You'll see that the 2nd date is not a valid datetime.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
September 19, 2016 at 10:20 am
I've played a little more (this is a nice diversion from trying to understand reduction and distribution in QlikView) and it appears to depend upon the use of the hyphens.
The following screen-shot is a little cramped, so I could fit it all in:
1 and 6 are invalid on my instance. 6 I certainly expect but 1 still has me puzzled. Fortunately I always use either YYYYMMDD or 'DD MMM YYYY', so my brief bout of panic over so much of my past work has abated.
But I would still like to know why 1 and 2 behave the way they do.
September 19, 2016 at 12:26 pm
BrainDonor (9/19/2016)
I've played a little more (this is a nice diversion from trying to understand reduction and distribution in QlikView) and it appears to depend upon the use of the hyphens.The following screen-shot is a little cramped, so I could fit it all in:
1 and 6 are invalid on my instance. 6 I certainly expect but 1 still has me puzzled. Fortunately I always use either YYYYMMDD or 'DD MMM YYYY', so my brief bout of panic over so much of my past work has abated.
But I would still like to know why 1 and 2 behave the way they do.
QlikView? Maybe it's causing all the problems?
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
September 20, 2016 at 5:54 am
Alvin Ramard (9/19/2016)
BrainDonor (9/19/2016)
I couldn't see any of the answers that matched what I believed I should be getting - then I played around a little.Where dates are concerned it is probably helpful to specify the date format in use, as this site has people from all over - and they might not be using the same date format as yourself.
That aside, a nice question.
With SQL Server, dates formatted as YYYY-XX-YY will always be YYYY-MM-DD,
YYYY-DD-MM is not a valid format with SQL Server.
This is true for the DATE, DATETIME2, and DATETIMEOFFSET types, but DATETIME, and SMALLDATETIME will interpret XXXX-XX-XX as YYYY-DD-MM if your date format is DMY. The following demonstrates this quite nicely, despite using the exact same literals, the two columns return two different values:
SET DATEFORMAT DMY;
DECLARE @DateTime DATETIME = '2012-02-01',
@Date DATE = '2012-02-01';
SELECT[Datetime] = EOMONTH( @Date, 2 ),
[Date] = EOMONTH( @DateTime, 2 );
For a dateformat of MDY, then both datatypes produce the same result:
SET DATEFORMAT MDY;
DECLARE @DateTime DATETIME = '2012-02-01',
@Date DATE = '2012-02-01';
SELECT[Datetime] = EOMONTH( @Date, 2 ),
[Date] = EOMONTH( @DateTime, 2 );
For DATETIME and SMALLDATETIME the only culture invariant format is YYYYMMDD
Viewing 15 posts - 1 through 15 (of 18 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy