Date Functions

  • Good one. I'm glad we finally have this function.

    I'm surprised it took so long!

    ---------------
    Mel. 😎

  • Toreador (10/24/2013)


    For me, a better answer is to subtract one from the first day of the next month, as this method will allow the same code to be run on other versions of SQLServer. The EOMONTH function is of no use if you are writing a system that has to run on SQL2008 as well.

    I agree. this method has been used for years, and has the added advantage of being slightly more portable. I'd say that makes it an excellent method as well.

  • sestell1 (10/24/2013)


    Toreador (10/24/2013)


    For me, a better answer is to subtract one from the first day of the next month, as this method will allow the same code to be run on other versions of SQLServer. The EOMONTH function is of no use if you are writing a system that has to run on SQL2008 as well.

    I agree. this method has been used for years, and has the added advantage of being slightly more portable. I'd say that makes it an excellent method as well.

    That's how I've always coded it, in T-SQL and even in Perl and Informix in my younger coding days.

    Tony
    ------------------------------------
    Are you suggesting coconuts migrate?

  • Toreador (10/24/2013)


    For me, a better answer is to subtract one from the first day of the next month, as this method will allow the same code to be run on other versions of SQLServer. The EOMONTH function is of no use if you are writing a system that has to run on SQL2008 as well.

    +1 for Toreador; however, it is good to see questions about new features so I can learn about them.



    Everything is awesome!

  • I think either asking a coworker or looking at a physical paper calendar are both excellent! 😉

  • Toreador (10/24/2013)


    For me, a better answer is to subtract one from the first day of the next month, as this method will allow the same code to be run on other versions of SQLServer. The EOMONTH function is of no use if you are writing a system that has to run on SQL2008 as well.

    Having to write code for multiple versions is what holds me back from using the latest and greatest. I still have a system that is on SQL server 2005 for gosh sakes.

  • OCTom (10/24/2013)


    Toreador (10/24/2013)


    For me, a better answer is to subtract one from the first day of the next month, as this method will allow the same code to be run on other versions of SQLServer. The EOMONTH function is of no use if you are writing a system that has to run on SQL2008 as well.

    Having to write code for multiple versions is what holds me back from using the latest and greatest. I still have a system that is on SQL server 2005 for gosh sakes.

    Same here. We have 2008 locally and 2005 remotely. If not for the 2005 servers, I would be using MERGE instead of INSERT and UPDATE a lot more often.

    Tony
    ------------------------------------
    Are you suggesting coconuts migrate?

  • Thank you! I learned a new helpful command today.

  • Thanks, we have needed this for some time. Glad to have it and the point!

    Not all gray hairs are Dinosaurs!

  • Good to know of the function exists but I still find it more useful to subtract, as this function only returns date; not date and time. I program in a datetime world.

  • doug.davidson (10/24/2013)


    Good to know of the function exists but I still find it more useful to subtract, as this function only returns date; not date and time. I program in a datetime world.

    So what time is it on the last day of the month? It's only worth the extra five bytes (DATETIME vs DATE) to store a time if it's relevant.

  • doug.davidson (10/24/2013)


    Good to know of the function exists but I still find it more useful to subtract, as this function only returns date; not date and time. I program in a datetime world.

    Same here. Need to know that last clock tick of the month sometimes too. Or write '<' earliest timestamp of next month.

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • I have to admit I was really tempted to answer "Ask a co-worker" even though I knew it would be incorrect. However, I decided to get the point instead.

  • One of every 100 SSC members believe that can "Create an array with the last day of every month", even when arrays is a feature not implemented in SQL Server yet. 😀

  • Easy, easy -- thanks, John!

Viewing 15 posts - 16 through 30 (of 35 total)

You must be logged in to reply to this topic. Login to reply