Can you improve this: Converting Year,Month,Day (all INT's) to DATETIME

I am trying to convert three INT values to a DATETTIME

The following TSQL works, but there must be a better way?

DECLARE @year INT = 1776, @month INT = 7, @day INT = 1
SELECT CONVERT(DATETIME, CONVERT(CHAR(4), @year)+'-'+CONVERT(CHAR(2), 
@month)+'-'+ CONVERT(CHAR(2), @day))

Thanks

Russell Mangel
Las Vegas, NV 

0
Russell
2/6/2010 11:42:23 AM
sqlserver.programming 1873 articles. 0 followers. Follow

2 Replies
1097 Views

Similar Articles

[PageSpeed] 51

SELECT CONVERT(DATETIME, RTRIM(@year*10000 + @month*100 + @day))

http://www.eggheadcafe.com/software/aspnet/31322028/convering-year-month-an.aspx



"Russell Mangel" <russell@tymer.net> wrote in message 
news:ufJY0FypKHA.4532@TK2MSFTNGP05.phx.gbl...
>I am trying to convert three INT values to a DATETTIME
>
> The following TSQL works, but there must be a better way?
>
> DECLARE @year INT = 1776, @month INT = 7, @day INT = 1
> SELECT CONVERT(DATETIME, CONVERT(CHAR(4), @year)+'-'+CONVERT(CHAR(2), 
> @month)+'-'+ CONVERT(CHAR(2), @day))
>
> Thanks
>
> Russell Mangel
> Las Vegas, NV 


0
Jellifish
2/6/2010 2:36:08 PM
SELECT DATEADD(MONTH, 12 * @Year - 22801 + @Month, @Day - 1)

//Peter


"Russell Mangel" <russell@tymer.net> wrote in message 
news:ufJY0FypKHA.4532@TK2MSFTNGP05.phx.gbl...
> I am trying to convert three INT values to a DATETTIME
>
> The following TSQL works, but there must be a better way?
>
> DECLARE @year INT = 1776, @month INT = 7, @day INT = 1
> SELECT CONVERT(DATETIME, CONVERT(CHAR(4), @year)+'-'+CONVERT(CHAR(2), 
> @month)+'-'+ CONVERT(CHAR(2), @day))
>
> Thanks
>
> Russell Mangel
> Las Vegas, NV 

0
Peso
2/9/2010 11:34:19 AM
Reply:

Similar Artilces:

Can you insert a picture into a specific cell?
Or do they only "float" on the page. Marc They float over the worksheet, but you can adjust the size so that it seems to fit a cell exactly. If you insert a picture, you can hold the alt-key down while you move/resize the picture. When it gets close to the edge of a cell, it'll snap-to that edge. Marc wrote: > > Or do they only "float" on the page. > > Marc -- Dave Peterson ...

Can't insert Char(1) into SQL Server from Stored Procedure
Hello I am trying to insert a char(1) field into a table from an ASP.Net/C# application. At first I was inserting rows into the table but none of the columns that I was inserting the rows into were char(1) columns, they were mostly int and varchar columns. Then I found out that there was one column in the list that was not supposed to be an int column but instead it was supposed to be one of the char(1) columns into the table. So I replaced the int column in the list with the char(1) column and since the value of the char(1) column resulted from a CheckBox ('Y...

Can E-mail recipient policy be linked to the OU membership?
Running Exchange 2003 (mixed mode) and Windows 2003 server (Windows 2000 mixed mode): I'd like to create a e-mail recipient policy that is linked to the different OU's that are created on the system. Is it possible to link the policy to a specific OU or do I need to create groups on the AD to control which recipients a policy applies to? Martin Moustgaard Yes, you can create a recipient policy that looks to just a specific OU. It is done through LDAP queries. Here are some references to articles and whitepapers that discuss how to work with recipient policies. 249299.KB.EN-US HO...

Can't open 2005 data file after reinstalling Money 2005
I am experiencing a recurring problem. I have had to reinstall Windows XP and MS Money 2005. I am now unable to open my previously converted 2005 file or restore any backup version. I consistently get the following error message: "Money cannot locate filename or cannot open it, possibly because it is a read-only file, you do not have permission to change it, or your disk drive is write- protected. If you have chosen the correct file and it cannot be accessed, you will need to click OK and then Restore your most recent backup file." Any help or thoughts would be greatly ap...

Month problem
I have some code where I calculate this month minus 2 month. This goes fine until I get to august. When I use DateSerial to deduct 2 month I get to July, and this makes no sence. I made the following testcode. Sub StrangeMonth() Dim MyDate As Date MyDate = #8/31/2010# MsgBox DatePart("m", DateSerial(Year(MyDate), _ Month(MyDate) - 1, Day(MyDate))) ' MsgBox = 7 MsgBox DatePart("m", DateSerial(Year(MyDate), _ Month(MyDate) - 2, Day(MyDate))) ' MsgBox = 7 MsgBox DatePart(&qu...

can i download lxce serv.exe
want to open message lxce serv.exe using windows xp ...

Converting Opportunity to Account
How do I convert an Opportunity to a Account? Thanks This is not possible, opportunities are opportunities for existing accounts/contacts. This is why when you convert a Lead to an Opportunity you must select the potential customer also. Regards Dan "circulent" wrote: > How do I convert an Opportunity to a Account? Thanks how would I select a potential customer? does this mean I have to create an account for them as well? it wouldnt make sense since they may not ending up being an account. thoughts? "Dan Quinton" wrote: > This is not possible, opportunities...

how many receivers i can add
i want to use outlook send 2000 thousands emails to 2000 peoples at the same time. can i put them all in the recivers and send them at one time? thank you for you help ...

With and import tool can you change only item description?
Is there a way to change only the item description on a large quanity of items. What about the extended description? Thanks for your help. Use the MS SQL Data Import Tool by EMS. $65.00. The QSImport Tool available to download from Microsoft will probably work but is not supported by Microsoft. Kinnard L. Kohler Business Machines Systems 6101 South Shackleford Road Little Rock, AR 72204-8606 (T) 501-375-8380 (F) 501-375-0043 (Cell) 501-412-5686 Email: kinnard@removebmsar.com "Lisa" wrote: > Is there a way to change only the item description on a large quanity of >...

Can i use conditional formating on a cell when it contains a formula?
I am trying a "conditional formatting" on a cell that contains formula, but it didn't work. "If cell value is equal to 0 then font - white" This doesn't work, stays always. If i use this condition on a cell without formula it works just fine. Thank -- si ----------------------------------------------------------------------- sit's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=262 View this thread: http://www.excelforum.com/showthread.php?threadid=26784 Hi are you sure your formula returns an exact zero?. Could you post the formul...

sort by day of the week?
Excel 2002 I have 10 years of grain prices...one price for each trading day of th year. In 'A' we have the date, in 'B' the price. What I need to do i get a list of prices for Mondays, Tuesdays, Wednesdays, etc... Possible? (I really, really don't want to do this manually) Than -- Message posted from http://www.ExcelForum.com add a column = weekday(a1,1) etc and do a sort on this colum -- Message posted from http://www.ExcelForum.com Thank you. You saved me 3 or 4 hours of excruciating data entry. Thi was the last step of a vital report. Now I can do my char...

Can't configure Outlook Express
I had Outlook express set up for the Money newsgroup, but somehow I lost it. Now I even forgot how to set it up again. I always get the error message saying "server cannot be found". The server name I typed in was microsoft.public.money, and I am not sure what should I type in here Thanks for help In microsoft.public.money, wj wrote: >I had Outlook express set up for the Money newsgroup, but >somehow I lost it. Now I even forgot how to set it up >again. I always get the error message saying "server >cannot be found". The server name I typed in was &g...

Symbol Updating Only Every Few Days (if at all)
Using Money 2006, and have a symbol "VLO" that is only updating every few days. This stock was a duplicate (downloaded transaction created a new version of the same stock - my fault not clicking correct choice when asked). I've removed the symbol from the stock entry that was downloaded, renamed this entry to something bogus, deleting this renamed stock "from all accounts", then added the symbol back to the original VLO stock that I've been tracking for years. Now the stock just says "unch" in the portfolio view, and the price history is only updat...

How do I convert a concatenated value into a know value
Hi all I am trying to get the results of a multiple input table, which get concatenated, read out as usable values eg. If the concatenated values are for example *llbbt* , I need this t be read as Simon, or *lbttd* must result in Fred etc... I will attact the spreadsheet. Thanks Colli Attachment filename: book3.xls Download attachment: http://www.excelforum.com/attachment.php?postid=54116 -- Message posted from http://www.ExcelForum.com You are probably better off by describing your problem, most regulars won't open files.. -- Regards, Peo Sjoblo...

what printers can run Vista
just purchased a dell which came with Vista on it. now my printer (HP 5550 deskjet) won't print. I need to find a new printer that i can hook up to the computer. This is an Access newsgroup. We help with questions related to Microsoft Access - the database application that is part of MS Office Professional. -- Rick B "monroe" <monroe@discussions.microsoft.com> wrote in message news:AC746826-251A-4097-AF88-2805BCDE7DEC@microsoft.com... > just purchased a dell which came with Vista on it. now my printer (HP > 5550 > deskjet) won't print. I need to...

convert to stored proc
Hello. I have been given a conversion assignment to convert Access db (frontend) with sql server 2005 backend to be included in a new webapp that is being constructed. Unfortunately, my stored proc creating is a bit weak and I'm not afraid to admit it. With that said, I came across an Access query that is puzzling me. Here it is; SELECT Purchase Orders *, POSO Relationships.SONumber AS RelatedSONumber, IIf([POSOType], [POSOType], 'Standard') AS POSOTypeFull, POSORelationships.MTXRMA, POSORelationships.SupplierRMA, POSORelationships.POSOType FROM PurchaseOrders ...

Recommendations Please: Software That Can Backup Outlook While It is Open/Running
As the subject says. There are lots of packages that will backup the pst, etc. once Outloook is closed, but some products claim to do it while Outlook is open. Any suggestions on products that actually do this and do it properly? If the product can safely backup over the network to a server and can do incremental/update backups throughout the day, I'd really like to hear about it. Thanks. ...

Can not open PDFs
I'm using Outlook Express,when I receive e-mail with pdf attachments I can not open or save the PDF files I can see that the file is there but nothing happen. thanks Cesar Open the message in question. Is there a informational bar across the top that states Outlook Express blocked access to the file? If yes, select Tool > Options > Security tab and uncheck the second box from the top concerning attachments. "Cesar Calderon" <anonymous@discussions.microsoft.com> wrote in message news:29c4e01c465ca$a76ec470$a501280a@phx.gbl... > I'm using Outlook Express,...

How can I sum only amounts that are in BOLD format within a column
Hi! I need to get a total from a worksheet that has hundreds of amounts in it. However, I only need the total of the amounts that were marked with have BOLD font. Please help me I don't have much experience with EXCEL. Thank you very much! W a n d a try this for column D Sub sumbold() x = Cells(Rows.Count, "d").End(xlUp).Row For Each c In Range(Cells(2, 4), Cells(x, 4)) If c.Font.Bold Then mysum = mysum + c Next MsgBox mysum End Sub -- Don Guillett SalesAid Software donaldb@281.com "Wanda" <Wanda@discussions.microsoft.com> wrote in message news:89A268A6-...

Can't use openURL or access internet on some locations
I have previously raised a question where openUrl threw an exception in a specific office location. However the problem I have now is that the application just freeze when I call openURL. It seems as it is waiting for something. This only happens at one company so far the company does have a proxy but so do I at work and I have no problems. I have also tried the Microsoft TEAR sample and it behaves the exact same way, it says "Opening internet...Connection made" and then it just stops. If I run it on my computer it gets the webpage and everything finishes ok. I have tried to set t...

Chart help Hide Months
I have a data sheet that has historical data, I only want to chart 13 months instead of all the data. Is there a way to do this? hide em -- Don Guillett SalesAid Software dguillett1@austin.rr.com "lmossolle@nc.rr.com" <lmossollencrrcom@discussions.microsoft.com> wrote in message news:EEF19AB1-9092-4B52-868E-574232FC8AC0@microsoft.com... >I have a data sheet that has historical data, I only want to chart 13 >months > instead of all the data. Is there a way to do this? Hi, If your data increase each month have a look at Jon Peltier's example of dynamic na...

OWA user can only see subject
Hello friends, OWA users are unable to see their mail. Only Subject field is visible, without mail contents(No message is visible). Our outlook is working fine. Any ideas why this is happening and how we can solve this. Regards Guri ...

Can I change the Comment Box arrow connection point?
Is there any way to change the point on a Comment Box where the tail end of the arrow it attached? Until today, all of the arrows in my workbook had been attached to the upper left-hand corner of the Comment Boxes. Today, I noticed that one of them is attached to the upper right-hand corner. I have no idea how that happened, but it seems to indicate that the attachment point can be moved. Can the arrow be attached to the center of the Comment Box so that when it is moved around, the tail always comes from the closest point? Comments have a habit of moving around. To reset all to default po...

ColHdgs=Years show up as series not as legend labels
We're unable to generate a usable chart from our table with year (numeric values) as the column headings and numerical values as th data series to be charted. Using Office2002. e.g. 2001 2002 2003 2004 ........10000 8000 12000 11500 Both ranges appear as data series. I've tried extensive variations of possibilities in the Chart Wizar Step 2 Series dialogue box, with no luck. The only way I can make the years work as labels is to change to tex in the table, e.g. '2001 '2002 '2003 '2004 But that's not optimal since the data is imported as end of fisca pe...

PS2007
I was trying to troubleshoot a problem and checking to see if services in SharePoint Central Admin were running. I must have accidently clicked when rolling over the start and stop as I got kicked out of Central Admin and can't get back in. How does one restart if stopped or regain access??? Services generally allow you to stop and restart. Where do I go to restore access. Everything seems to be running ok, but it wont let me access Central Admin in the server. Anybody know how to restore this? Hi Rick. Fear not, thankfully, there is a stsadm command to help start the ...