Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Date Puzzle


Date Puzzle

Author
Message
SanDroid
SanDroid
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1414 Visits: 1046
GPO (10/27/2010)
spelling and gramer

:-P

Glad that did not go unoticed. Hehe
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16513 Visits: 13208
SanDroid (10/27/2010)
da-zero (10/27/2010)

Have smileys totally lost their value nowadays?


I am not certain. Are they? w00t
I just used your response as a jumping off point. :-P
I know you are not the one moderating the Question of the Day.Wow
I did not mean it to be personal and thought you would realize that. Sick

My point was/is nobody realy moderates the QOTD, and that is taking focus away from good questions that promote learning and placing it on bad spelling and gramer.

Of course if it was not for all these Forum posts, how many people would have a status above rookie on this site?

BTW: What was the intermediary language between you native language and English as the 3rd language? Was it C++, COBOL, QBASIC, SQL? Cool



The funny thing is that I forgot a smiley in my response :-)
Without it, the response seems quite harsh. When will the internet have intonation?

ps: my 2nd language is French Alien (sadly no smiley of a mime with a baguette)



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8337 Visits: 11581
SanDroid (10/27/2010)
Hugo Kornelis (10/27/2010)
[quote][b]And if you ever install SQL Server on a German OS, acccepting all defaults, you'll find that the Server language also defaults to German..


Is that becuase of the Laguage of the OS, or the installing users regional settings in Control Panel?

Good question, but I can't answer it. All my SQL Server installations thus far have been on Dutch operating systems, and since there is no Dutch version of SQL Server, that means SQL Server defaults to US English settings.

When you responded to my inital post saying you disagreed that this was a good question and stated that the code was unsafe.

I never said that I disagree that this is a good question. I did say that I don't share your enthousiasm. I also said that the code was not safe outside US English.

It's not my habit to rate the questions here, except when I consider them to be exceptionally good or exceptionally bad. But you misunderstood me, ad maybe you're not the only one, so I'll set the record straight. In y opinion, this question is neither good, nor bad, but mediocre. The knowledge tested is so basic that I'd expect almost everyone to know it, and the answer options don't even include the distractors that might be believable (as pointed out by others in this thread). But on the positive side, there is ambiguity in the question text, and apart from the bad practice with the date format, there is no error in the code.

What was that supposed to make me or the author think?
Ich zweifele, er dachte, dass es ein Kompliment war.

Machine translation still isn't perfect. Correct German would be "Ich bezweifle, dass er dachte, es war ein Kompliment". But my English is much better than my German, so unless you're good at Dutch, I suggest we stick to English.

To answer your question - what my comment was supposed to make you think, is exactly what I wrote in my comment: that I don't share your enthousiasm, and that the date format used in not locale-safe.

And that concludes my final comments on this subset of the discussion, as this whole "who said what and who meant what when he said that" discussion adds nothing. I'm here to discuss the nuts and bolts of SQL Server.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Dan Guzman - Not the MVP
Dan Guzman - Not the MVP
Right there with Babe
Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)

Group: General Forum Members
Points: 724 Visits: 736
So, is this the simplest and quickest way to get the last day of any month?

DATEADD(MONTH,x,'2010-Jan-01')


Where x is the month you are looking for the last day.

I've seen a lot of code over the years that performs some sort of find the first day of the month after the month in question, then subtract 1 day. Seems totally unnecessary with this function.
SanDroid
SanDroid
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1414 Visits: 1046
Hugo Kornelis (10/27/2010)
[quote]SanDroid (10/27/2010)
[quote]Hugo Kornelis (10/27/2010)
[quote][b]And if you ever install SQL Server on a German OS, acccepting all defaults, you'll find that the Server language also defaults to German..


that means SQL Server defaults to US English settings.



I'm here to discuss the nuts


You have done well in contradicting your own "facts" in your own posts about the nuts of SQL installs. Is the information in your other post is as correct.

FYI: I lived in Bad Kreuznach for five years. I have no need for machine translators to type German (not Dutch) poorly.
Michael Valentine Jones
Michael Valentine Jones
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3264 Visits: 11771
Dan Guzman - Not the MVP (10/27/2010)
So, is this the simplest and quickest way to get the last day of any month?

DATEADD(MONTH,x,'2010-Jan-01')


Where x is the month you are looking for the last day.

I've seen a lot of code over the years that performs some sort of find the first day of the month after the month in question, then subtract 1 day. Seems totally unnecessary with this function.


Not sure if you mis-typed that, but it is fairly obvious that will return the FIRST day of the month AFTER x. For example, if x=10, it will return 2010-11-01 00:00:00.000.

This is the standard and most efficient way of getting the last day of the month a particular date is in:
select LastDay = dateadd(mm,datediff(mm,-1,getdate()),-1) 


Result:
LastDay
-----------------------
2010-10-31 00:00:00.000

Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16513 Visits: 13208
SanDroid (10/27/2010)

You have done well in contradicting your own "facts" in your own posts about the nuts of SQL installs. Is the information in your other post is as correct.


Rolleyes

German: there exists a German version of SQL Server --> default language is German
Dutch: there is no Dutch version of SQL Server --> default language is US English



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
UMG Developer
UMG Developer
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2280 Visits: 2204
Thanks for the question, though I agree with the other comments about the date string not working for all languages/settings.
michael.kaufmann
michael.kaufmann
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1293 Visits: 1082
Is that becuase of the Laguage of the OS, or the installing users regional settings in Control Panel?


That depends:
If you install SQL Server running under the SYSTEM (machine) account, it will pick up the OS's regional settings (so if your OS is German, the regional settings for the SYSTEM account are German ...).
If you install SQL Server running under a dedicated account, it will use the regional settings of that particular user/account.

Regards,
Michael
Dan Guzman - Not the MVP
Dan Guzman - Not the MVP
Right there with Babe
Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)Right there with Babe (724 reputation)

Group: General Forum Members
Points: 724 Visits: 736
Michael Valentine Jones (10/27/2010)
Dan Guzman - Not the MVP (10/27/2010)
So, is this the simplest and quickest way to get the last day of any month?

DATEADD(MONTH,x,'2010-Jan-01')


Where x is the month you are looking for the last day.

I've seen a lot of code over the years that performs some sort of find the first day of the month after the month in question, then subtract 1 day. Seems totally unnecessary with this function.


Not sure if you mis-typed that, but it is fairly obvious that will return the FIRST day of the month AFTER x. For example, if x=10, it will return 2010-11-01 00:00:00.000.

This is the standard and most efficient way of getting the last day of the month a particular date is in:
select LastDay = dateadd(mm,datediff(mm,-1,getdate()),-1) 


Result:
LastDay
-----------------------
2010-10-31 00:00:00.000





You are correct, I meant January 31st. so:

DATEADD(MONTH,x-1,'2010-Jan-31') so that x is the month your looking for,

or for last day of the current month:

DATEADD(MONTH,MONTH(GETDATE())-1,'2010-Jan-31')

I even think

DATEADD(MONTH,MONTH(GETDATE())-1,CAST(YEAR(GETDATE()) AS VARCHAR(4)) +'-Jan-31')

is easier to read than the one you mention, with the DATEDIFF, but that's just me.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search