Solved

T-SQL month  Datepart issue

Posted on 2008-10-10
1
1,440 Views
Last Modified: 2010-05-18
Hi, I have a datatype of DateTime.

I want to parse out parts of the value to build my custom string, e.g.
cast(datepart(dd, BeginTime) as char(2)) + '/' + cast(datepart(mm, BeginTime) as char(2))

Problem is I only seem to be able to get the month in a 1 number format, I want august to be 08 and not just 8.  Thought this would be very easy but I am stuck.

any ideas?

Thanks.
0
Comment
Question by:sublimation
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 22685718
why not do it like this:
CONVERT(VARCHAR(5), BeginTime, 103)

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

8 Experts available now in Live!

Get 1:1 Help Now