SQL Server Syntax Question

Posted on 2014-07-10
Last Modified: 2014-07-10
I need to pull MM/YYYY as Datetime data type from a date field. How do I do it?

 Select RIGHT(CONVERT(VARCHAR(10), GETDATE(), 103), 7) - This gives me varchar; But the column is defined as Datetime in the table. How do  convert this to Datetime?

Question by:rustypoot
    LVL 21

    Assisted Solution

    by:Randy Poole
    MM/YYYY is not a valid for a datetime field, since you also need DD
    LVL 39

    Accepted Solution

    DateTime data types have a day as well, you can't have have mm/yyyy.

    If you don't care about the day, you can set them all to be the first day of the month.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now