Thursday, July 21, 2011

SQL Date Queries

SELECT DATEADD(dd,-(DAY(GETDATE())-1),GETDATE()) AS FirstDayOfCurrentMonth

DECLARE @mydate DATETIMESELECT @mydate = GETDATE()

SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)),@mydate),101) ,'Last Day of Previous Month'

UNION

SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101) AS Date_Value,'First Day of Current Month' AS Date_Type

UNION

SELECT CONVERT(VARCHAR(25),@mydate,101) AS Date_Value, 'Today' AS Date_Type

UNION

SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,'Last Day of Current Month'

UNION

SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,1,@mydate)),101) ,'First Day of Next Month'


Reference: http://blog.sqlauthority.com/2007/05/13/sql-server-query-to-find-first-and-last-day-of-current-month/

25 comments:

Anonymous said...

Hi there mates, how is the whole thing, and what you want
to say regarding this article, in my view its really awesome in favor of me.


my page :: estimations Gauteng
My site > estimations Gauteng

Anonymous said...

hello there and thank you for your information – I've definitely picked up anything new from right here. I did however expertise several technical issues using this website, as I experienced to reload the web site a lot of times previous to I could get it to load correctly. I had been wondering if your hosting is OK? Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and could damage your quality score if advertising and marketing with Adwords. Well I am adding this RSS to my email and could look out for a lot more of your respective interesting content. Make sure you update this again soon.

Here is my homepage :: baby colic

Anonymous said...

I am extremely inspired along with your writing skills as smartly as with the
layout to your blog. Is that this a paid topic or did you customize it yourself?
Anyway stay up the excellent high quality writing, it is uncommon to peer
a nice weblog like this one these days..

my homepage: Institution Johannesburg
my site: salons Johannesburg

Anonymous said...

My brother suggested I might like this web site. He was entirely right.
This post truly made my day. You can not imagine simply how much time I had spent for this information!
Thanks!

Look into my site - computer training Pietermaritzburg
my webpage - computer lab hire Pietermaritzburg

Anonymous said...

Hi, i think that i saw you visited my weblog thus i came to return the prefer?

.I am attempting to to find issues to improve my site!
I guess its adequate to use a few of your concepts!

!

Feel free to visit my blog post crime scene clean up Gauteng

Anonymous said...

I think the admin of this website is actually working hard in
support of his web page, because here every information is quality based data.



Here is my blog post :: diamond grading

Anonymous said...

I'm really enjoying the theme/design of your blog. Do you ever run into any web browser compatibility issues? A number of my blog readers have complained about my website not operating correctly in Explorer but looks great in Opera. Do you have any ideas to help fix this issue?

my webpage ... microsoft office training Pietermaritzburg

Anonymous said...

It is appropriate time to make some plans for the future
and it's time to be happy. I have learn this publish and if I may I want to recommend you some fascinating things or advice. Maybe you could write next articles relating to this article. I wish to read even more issues approximately it!

Here is my blog; waxing Cape Town

Anonymous said...

I read this article fully about the comparison of newest
and preceding technologies, it's awesome article.

My web page ... laser hair removal Cape Town

Anonymous said...

Undeniably imagine that that you said. Your favourite justification seemed to
be at the internet the simplest factor to be mindful of.
I say to you, I certainly get irked at the same time as other people think about concerns that they
just don't know about. You managed to hit the nail upon the top and also outlined out the whole thing with no need side-effects , folks could take a signal. Will likely be again to get more. Thank you

My weblog ... more information

Anonymous said...

I read this post completely on the topic of the difference of hottest and earlier technologies, it's remarkable article.

my homepage :: website

Anonymous said...

I’m not that much of a online reader to be honest
but your sites really nice, keep it up! I'll go ahead and bookmark your site to come back later. All the best

Here is my web site ... more Info

Anonymous said...

I feel this is among the such a lot important info for me.
And i am happy studying your article. However want to
observation on few basic issues, The web site style is perfect, the articles is really great : D.
Good task, cheers

Also visit my page :: more information

Anonymous said...

When someone writes an piece of writing he/she
maintains the thought of a user in his/her mind that how
a user can know it. Therefore that's why this article is perfect. Thanks!

My blog post; more info

Anonymous said...

Nice post. I was checking continuously this blog and I'm inspired! Very helpful information specially the last section :) I handle such info much. I was seeking this particular info for a very long time. Thanks and good luck.

Look at my web blog: know more

Anonymous said...

These are genuinely great ideas in about blogging.
You have touched some nice things here. Any way keep up wrinting.


Have a look at my site: site

Anonymous said...

Hey there! Do you know if they make any plugins to
assist with Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm
not seeing very good results. If you know of any please share.
Kudos!

Here is my blog post; website

Anonymous said...

Hi there! This is my first visit to your blog! We are a
team of volunteers and starting a new initiative in a community in the same niche.
Your blog provided us valuable information to work on.
You have done a marvellous job!

My homepage :: click here

Anonymous said...

Thanks for another magnificent post. The place else could anybody get that type of info in such a
perfect way of writing? I've a presentation subsequent week, and I am at the look for such info.

Feel free to surf to my blog post ... website

Anonymous said...

Hey very interesting blog!

my web site: waste management Cape Town

Anonymous said...

It's hard to find knowledgeable people for this subject, but you sound like you know what you're talking
about! Thanks

Here is my weblog ... property management services & development KwaZulu Natal

Anonymous said...

Hi there everyone, it's my first go to see at this website, and piece of writing is really fruitful designed for me, keep up posting such articles or reviews.

Feel free to visit my webpage - more info

Anonymous said...

The Razer Goliathus is a amazing mouse mat and the League of Legends fight scene actually
provides a great glance to it regardless of whether you're not a lover with the sport genre. The keyboard stays superb and the make good quality impeccable. For your pinewood trees, occasionally it had been difficult to get a transparent view of your sea when i tramped together this phase of Route 113.

Have a look at my web site League Of legends Hack

Anonymous said...

Why people still make use of to read news papers when in
this technological globe the whole thing is presented on net?


my website: edentata

Anonymous said...

I seriously love your blog.. Pleasant colors & theme.
Did you build this amazing site yourself? Please reply back as I'm looking to create my own personal site and would like to find out where you got this from or what the theme is called. Cheers!

my web site statics to marketing social media services