[Last Call] Learn how to a build a cloud-first strategyRegister Now


SQL Server Syntax Question

Posted on 2014-07-10
Medium Priority
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
Randy Poole earned 1000 total points
ID: 40189129
MM/YYYY is not a valid for a datetime field, since you also need DD
LVL 41

Accepted Solution

Kyle Abrahams earned 1000 total points
ID: 40189132
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.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

829 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