|
|
CASTing a date
I have the following DECLARE that works fine but I need to handle times when
the day of a date is not = 1 and @Month passed is less than 10 so the date
gets '0x' for month or day. Below is my current CAST.
DECLARE @StartMoth date;
SET @StartMonth = CAST(CAST(@Year as char(4)) + CAST(@Month as char(2)) +
'01');
Thanks.
--
David
|
|
0
|
|
|
|
Reply
|
Utf
|
8/26/2010 10:09:03 PM |
|
Hi David,
I think it would be easier if you had one parameter of datetime. A datetime
(or date) could be converted directly to the format that you want with
convert.
With a single date(time) parameter you could do the following
--- this just to make as if I had a parameter of datetime
declare @myParameter datetime
set @myParameter = getdate()
--- end code for make as if I had a parameter
select convert(varchar, @d, 112) MyDate
the response is
MyDate
--------
20100902
In this example I build a date from integers and then cast it with convert
to get the format that you want. Note that I used varchars instead of chars
as you did.
declare @MyDay int = 5
declare @MyMonth int = 9
declare @MyYear int = 10
declare @MyDateStr varchar(10)
declare @MyDate datetime
set @MydateStr = cast(@MyYear as varchar(4)) + '/' + CAST(@MyMonth as
varchar(2)) + '/' + CAST(@MyDay as varchar(2))
set @MyDate = CONVERT(datetime, @MydateStr, 11)
select convert(varchar, @MyDate, 112) MyDate
Mike
http://www.homemadepride.com
"DavidC" <dlchase@lifetimeinc.com> a écrit dans le message de
news:3F00F204-619F-42AE-81AD-4EDBF4A50244@microsoft.com...
>I have the following DECLARE that works fine but I need to handle times
>when
> the day of a date is not = 1 and @Month passed is less than 10 so the date
> gets '0x' for month or day. Below is my current CAST.
>
> DECLARE @StartMoth date;
> SET @StartMonth = CAST(CAST(@Year as char(4)) + CAST(@Month as char(2)) +
> '01');
>
>
> Thanks.
> --
> David
|
|
0
|
|
|
|
Reply
|
Mike
|
9/2/2010 8:15:50 PM
|
|
|
1 Replies
223 Views
(page loaded in 0.032 seconds)
Similiar Articles: ObjectDataSource and null datetime parameter - microsoft.public ...After that the user will be able to > filter down the results by adding date ranges for startDate & endDate, > an integer value for tonality and a string for companyName. Cast to Boolean - microsoft.public.access.queriesObjectDataSource and null datetime parameter - microsoft.public ..... Web.UI.Page.ProcessRequestMain(Boolean > includeStagesBeforeAsyncPoint, Boolean ... CASTing a date ... Automate Change of the format of a field to short date for export ...The solution is to explicitly cast the date field as a Text, using the Format() function. Rather than exporting [CMMonth] use an expression in the query: ExpCMMonth ... Convert Integer to Date in Access ADP Project - microsoft.public ...One of the tables contains a field > that > stores the date as an integer. ... is m.p.access.adp.sqlserver. > > As for your question, use the Convert or the Cast ... Enter date range in a form then run query - microsoft.public ...I want the query to reference an open form for the date range. ... CAST as Date time, but then you get a conversion error when I run the query. ... Recurring Date on 2 Week Interval - microsoft.public.sqlserver ...I know the first date, and I want to know all the future pay dates for ... SELECT DATEADD(DD, (14 * S.seq), CAST('2010-01-01' AS DATE)) FROM Series AS S WHERE S.seq ... Convert Date to MM/DD/YYYY Format - microsoft.public.sqlserver ...Plamen Ratchev wrote: >Style 110 will convert to MM-DD-YYYY: > >SELECT CONVERT(VARCHAR(10), CAST('2009-01-06' AS DATE),110) AS mmddyyyy; > >/* > >mmddyyyy ... how to dateadd with bigint - microsoft.public.sqlserver ...i have a list of unix timestamps that i need to convert to datetimes. 16699435200 is the largest number. SELECT DATEADD(minute, CAST(16699435200... I got an error - microsoft.public.dotnet.framework.aspnet ...db sqlserver 2008, datanascita means "birth date" and it is a date type on the db ... come up with something else, because apparently that variable type cannot be cast ... Remove time from date upon export to csv - microsoft.public.access ...I cannot remove the time from the date when exporting invoice data to a csv file. ... this, other than Albert Kallal's most recent suggestion about explicitly casting the ... SQL Cast Date - SQL Server PlanetUsing SQL Server 2008 This first option of removing the date uses the SQL Server 2008 method. This will return only the date or only the time: If you're not... TM Tractor Parts Quality New and Replacement Parts for McCormick ...Use the chart on the right to translate the letter code into a year. For example, this picture shows a cylinder block cast date of 8*26*Q, which was August 26, 1947. CASTA string of the format 'nnnn-nn-nn' can be cast to DATE. (This string format corresponds to ODBC date format.) Value and range checking is performed; the input date ... Casting Date - Chevy Tech.InfoFig. 10.2 The Casting Date number is located under the valve cover between the valve cover hold down bolts as shown in WHITE numbers in Fig. 10.2. CAST and CONVERT - Microsoft Corporation: Software, Smartphones ...Each example retrieves the titles for those books that have a 3 in the first digit of year-to-date sales, and converts their ytd_sales to char(20).-- Use CAST. 7/24/2012 6:45:27 PM
|
|
|
|
|
|
|
|
|