Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Sunday, March 25, 2012

Copy Date Dimension

Hello Guys and Galls,

I have a fact table with two different keys referring to the same date dimension table. In a query you would use table aliassing to join the date dimension twice.

In AS I created a DSV with two aliasses of the date dimension table. Lets give um names:
- dim_ActivityDate
- dim_OrderDate

Now, I have created a dimension "Activity Date", based on the dim_ActivityDate dimension. I want to create a second dimension, "Order Date", which is a copy of the "Activity Date" dimension, but based on the dim_OrderDate alias from the DSV.

Is there an easy way to do this, or do I have to create the whole dimension using the wizard again?

Regards, Jeroen

Hi Jeroen,

No, you don't need to create two separate physical dimensions. You just need to create one dimension and add it to the cube more than once - a 'role playing dimension'. In Visual Studio just double click on your cube to edit it and assuming you have the dimension already added to the cube once, you just need to right-click on Dimensions box in the bottom-right-hand corner of the 'Cube Structure' tab and select 'Add Cube Dimension'. Add the date dimension again and you'll find that it gets added with a new name, which you can change to Order Date, and then if you go to the Dimension Usage tab you'll find you can join it to your measure group on the dim_OrderDate key column.

HTH,

Chris

|||Splendid! Thnx Chris.

Friday, February 24, 2012

Converting varchar to DateTime

Hi,

I wanted to convert the varchar to date time and here is what i am doing

DECLARE @.dt VARCHAR(20)

SET @.dt = '20070111' -- YYYYMMDD format

select CONVERT(datetime, @.dt, 120)

This works perfectly fine and the result would be- 2007-01-11 00:00:00.000

But if i changed my datetime format from YYYYMMDD to YYYYMMDDHHMM then this is failing and throwing

"Conversion failed when converting datetime from character string."

Can any one please let me know how do we achieve this?

~Mohan

YYYYMMDDHHMM is not recognized as a valid datetime string. For example, YYYMMDD HH:MM works.

|||

This is the Convert sintax:

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

The first parameter data_type is the required convertion type, of course including the length if required. The second parameter is the expression to convert, and to endding the last parameter is used to define the style in that you are passing the "expression" parameter.

In your code, the style parameter says 120 that corresponds to a ODBC Canonical format in this format: yyyy-mm-dd hh:miTongue Tieds.

Then, ?Does because a string with the format yyyymmdd can be converted to string?:

The YYYYMMDD is widely recognized ODBC String Format that can be used to convert a string to a SQL Server DateTime format. When you use this format, the convert function ignores the last parameter, because it's a standard format. Instead, YYYMMDDHHMM is not a SQL Server recognized format, by this you can not use this.

I recommend to you, to pass strings in the yyyy-mm-dd hh:miTongue Tieds format to be recognized by the CONVERT or CAST functions in SQL server.

Converting varchar to datetime

I have a sql server 2000 db that has a carchar field that is currently storying date data in the following format:

June 16

Can I convert that from varchar to datetime or smalldatetime without loss of data? And, if so, what adjustments do I have to make in my ado code to continue to allow my clients to add data. Currently they add date data by selecting a month from one dropdown and the day from another.

Thanks!Create another column and use CONVERT function to conver the date and store. Then delete the old column.

Sunday, February 19, 2012

converting varchar to date from asp.net to sort

for some odd reason our other programmer used varchar datatype to store dates. he claims it gives him more control. now i am trying to sort it based on date. so i create a procedure:

CREATE PROCEDURE GetAllWeekEnding

AS
Select convert(datetime, we) as we2 FROM tblArchive order by we2
GO

if i use the convert function in the procedure, i'll get an error msg when i run the code. this is the code i am using.

Dim MyConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringSQL"))
Dim MyCommand As SqlCommand

MyCommand = New SqlCommand("GetAllWeekEnding", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure
MyConnection.Open()

Dim mydr As SqlDataReader = MyCommand.ExecuteReader()
While mydr.Read()
DropDownList1.Items.Add(mydr("we2"))
End While

mydr.Close()
MyConnection.Close()

the error message is: No accessible overloaded 'ListItemCollection.Add' can be called without a narrowing conversion

any ideas?the .Add method expects a ListItem or a String. Try:

DropDownList1.Items.Add(mydr("we2").ToString())

Is there any reason you are not just binding to myDr?|||<<<<Is there any reason you are not just binding to myDr? >>>
yes, when i bind to the listbox, i am getting date and time.

i can get rid of the time by using:

While mydr.Read()
DropDownList1.Items.Add(Format(mydr("we2"), "M/dd/yyyy").ToString)
End While|||You could easily use Convert to convert the datetime to a date only (of type varchar()) in SQL Server in the SP if the only purpose of this SP is to feed this DDL.|||<<<<<You could easily use Convert to convert the datetime to a date only (of type varchar()) in SQL Server in the SP if the only purpose of this SP is to feed this DDL.
>>>>
the problem is that the date is already in varchar datatype in the database. on the aspx page, i want to load all the dates and i want it sorted by date. the only way for me to show the dates on the aspx page sorted by date is to convert the date from varchar to datetime, like this:

CREATE PROCEDURE GetAllWeekEnding

AS
Select Distinct convert(datetime, we) as we2 FROM tblArchive order by we2 desc
GO

once varchar is converted to datetime, it not only shows just the date but also time so i cannot bind it to a dropDownList.

if i just bind the orginal varchar on the DropDownList witout converting it to DateTime, it's not going to be sorted because you cannot sort a varchar like you sort a datetime|||CREATE PROCEDURE GetAllWeekEnding


AS
Select Distinct CONVERT(nvarchar(20),convert(datetime, we),101) as we2 FROM tblArchive order by convert(datetime, we) desc
GO

There is no rule that the representation you SELECT needs to be the same as you use to ORDER BY.

Converting varchar to date

Hi
Not being a coder I have no idea how to do this and existing posts dont
really help.
I have a table called 'Incoming' and a column called dateofbirth. The
format of the column is varchar. The values in the dateof birth column
are 01012000. When searching for particular dates I'm getting crap
results (because the query is crap too). I reckon I need to convert the
values in the column to dates so that my query can work.
All help gratefully accepted.
TIAHi
declare @.dt varchar(20)
set @.dt='01012000'
select
convert(datetime,substring(@.dt,5,4)+substring(@.dt,1,2)+substring(@.dt,3,2),112)
"jjaggii" <richardwsmit@.gmail.com> wrote in message
news:1152864481.073991.8460@.75g2000cwc.googlegroups.com...
> Hi
> Not being a coder I have no idea how to do this and existing posts dont
> really help.
> I have a table called 'Incoming' and a column called dateofbirth. The
> format of the column is varchar. The values in the dateof birth column
> are 01012000. When searching for particular dates I'm getting crap
> results (because the query is crap too). I reckon I need to convert the
> values in the column to dates so that my query can work.
> All help gratefully accepted.
> TIA
>|||Many thanks for that Uri :)
Uri Dimant wrote:
> Hi
> declare @.dt varchar(20)
> set @.dt='01012000'
> select
> convert(datetime,substring(@.dt,5,4)+substring(@.dt,1,2)+substring(@.dt,3,2),112)
>
>
> "jjaggii" <richardwsmit@.gmail.com> wrote in message
> news:1152864481.073991.8460@.75g2000cwc.googlegroups.com...
> > Hi
> > Not being a coder I have no idea how to do this and existing posts dont
> > really help.
> >
> > I have a table called 'Incoming' and a column called dateofbirth. The
> > format of the column is varchar. The values in the dateof birth column
> > are 01012000. When searching for particular dates I'm getting crap
> > results (because the query is crap too). I reckon I need to convert the
> > values in the column to dates so that my query can work.
> > All help gratefully accepted.
> > TIA
> >|||SELECT DATEOFBIRTH = CAST( SUBSTRING(dateofbirth,5,4) + '-' +
SUBSTRING(dateofbirth,1,2) + '-' +
SUBSTRING(dateofbirth,3,2)
AS DATETIME
)
FROM Incoming
M A Srinivas
jjaggii wrote:
> Hi
> Not being a coder I have no idea how to do this and existing posts dont
> really help.
> I have a table called 'Incoming' and a column called dateofbirth. The
> format of the column is varchar. The values in the dateof birth column
> are 01012000. When searching for particular dates I'm getting crap
> results (because the query is crap too). I reckon I need to convert the
> values in the column to dates so that my query can work.
> All help gratefully accepted.
> TIA

Converting varchar to date

Hi
Not being a coder I have no idea how to do this and existing posts dont
really help.
I have a table called 'Incoming' and a column called dateofbirth. The
format of the column is varchar. The values in the dateof birth column
are 01012000. When searching for particular dates I'm getting crap
results (because the query is crap too). I reckon I need to convert the
values in the column to dates so that my query can work.
All help gratefully accepted.
TIAHi
declare @.dt varchar(20)
set @.dt='01012000'
select
convert(datetime,substring(@.dt,5,4)+subs
tring(@.dt,1,2)+substring(@.dt,3,2),11
2)
"jjaggii" <richardwsmit@.gmail.com> wrote in message
news:1152864481.073991.8460@.75g2000cwc.googlegroups.com...
> Hi
> Not being a coder I have no idea how to do this and existing posts dont
> really help.
> I have a table called 'Incoming' and a column called dateofbirth. The
> format of the column is varchar. The values in the dateof birth column
> are 01012000. When searching for particular dates I'm getting crap
> results (because the query is crap too). I reckon I need to convert the
> values in the column to dates so that my query can work.
> All help gratefully accepted.
> TIA
>|||Many thanks for that Uri
Uri Dimant wrote:
[vbcol=seagreen]
> Hi
> declare @.dt varchar(20)
> set @.dt='01012000'
> select
> convert(datetime,substring(@.dt,5,4)+subs
tring(@.dt,1,2)+substring(@.dt,3,2),
112)
>
>
> "jjaggii" <richardwsmit@.gmail.com> wrote in message
> news:1152864481.073991.8460@.75g2000cwc.googlegroups.com...|||SELECT DATEOFBIRTH = CAST( SUBSTRING(dateofbirth,5,4) + '-' +
SUBSTRING(dateofbirth,1,2) + '-' +
SUBSTRING(dateofbirth,3,2)
AS DATETIME
)
FROM Incoming
M A Srinivas
jjaggii wrote:
> Hi
> Not being a coder I have no idea how to do this and existing posts dont
> really help.
> I have a table called 'Incoming' and a column called dateofbirth. The
> format of the column is varchar. The values in the dateof birth column
> are 01012000. When searching for particular dates I'm getting crap
> results (because the query is crap too). I reckon I need to convert the
> values in the column to dates so that my query can work.
> All help gratefully accepted.
> TIA

Converting US Date To UK Date in Reporting Services

I am using thise function in the Code Properties of my Report to convert US Date formats to UK Date format :

Public Function ConvertUSDateToUKDate(ByVal strUSDate As Object) As String
Dim strDay As String = strUSDate.Substring(3, 2)
Dim strMonth As String = strUSDate.Substring(0, 2)
Dim strYear As String = strUSDate.Substring(6, 4)
Dim strUKDate As String = strDay + "/" + strMonth + "/" + strYear + strUSDate.Substring(10, 12)
Return strUKDate
End Function

I keep getting an error with it, I'm not sure whether it is a VB.NET code error, or a Reporting Services error. Can anybody help?

Cheers,

Mike

Sorted this out :

Public Function ConvertUSDateToUKDate(ByVal strUSDate As String) As String
Dim strUKDate As String = ""
If Not (strUSDate = "") Then
Dim arrRateArray As String()
Dim arrSeparator As Char() = {"/"C}
arrRateArray = strUSDate.Split(arrSeparator)
Dim strMonth As String = arrRateArray(0)
Dim strDay As String = arrRateArray(1)
Dim strYear As String = arrRateArray(2).Substring(0, 4)
Dim strTime As String = arrRateArray(2).Substring(5, arrRateArray(2).Length - 5)
strUKDate = strDay + "/" + strMonth + "/" + strYear + " " + strTime
Else
strUKDate = ""
End If

converting unix dates

Hi,
Does anyone know of a quick an easy way of convertiing unix date serials eg
12815 to March 31 2005).
Any pointers appreciated
Thanks
SimonHi
I would have expected
select dateadd(ss, <UNIX_timestamp>, '19700101')
to have worked which implies 12815 either wrong or not a unix timestamp!!
John
"skilla31" wrote:

> Hi,
> Does anyone know of a quick an easy way of convertiing unix date serials e
g
> 12815 to March 31 2005).
> Any pointers appreciated
> Thanks
> Simon
>
>|||I suspect this isn't a standard Unix timestamp. Maybe 12815 represents
the number of days since some date. For example:
DECLARE @.t INTEGER
SET @.t = 12815
SELECT DATEADD(DAY,@.t,'19691231')
Result:
2005-01-31 00:00:00.000
(1 row(s) affected)
or:
SELECT DATEADD(DAY,@.t,'19700228')
Result:
2005-03-31 00:00:00.000
(1 row(s) affected)
DATEADD is probably the function you need in any case.
David Portas
SQL Server MVP
--|||Thanks
Jens, John & David, that solved my problem. Turns out I got the number wrong
should've been 12873
Thanks
Simon
"skilla31" <simon@.ris.org.uk> wrote in message
news:uN56AxOQFHA.3496@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Does anyone know of a quick an easy way of convertiing unix date serials
> eg 12815 to March 31 2005).
> Any pointers appreciated
> Thanks
> Simon
>|||"skilla31" <simon@.ris.org.uk> wrote in message
news:uN56AxOQFHA.3496@.TK2MSFTNGP12.phx.gbl...

> Hi,
> Does anyone know of a quick an easy way of convertiing unix date serials
> eg 12815 to March 31 2005).
SELECT DATEADD(d, 12815, '01 Jan 1970')

converting to date only

I have a function on a MSSQL 2000 db like the following:

create function GetDateOnly (@.pInputDate datetime)
returns datetime
as
begin
return cast(convert(varchar(10), @.pInputDate, 111) as datetime)
end

which returns the date with the time all zeros ( '2006-05-09 00:00:00' ). I tried to implement this same function on an MSSQL 7 server and I get errors.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'function'.

How can I code something similar in version 7? I'm assuming it's a version difference that is causing my problems.

Thanks,
Randy7.0 did not support user-defined functions.

You could write a stored proc with an OUTPUT parameter to do this, but you could not include it in a SELECT statement as you can with a function.

You will probably need to code the logic each time you need it. But I suggest you use this formula instead, which is more efficient than the CONVERT method you are using:

create function GetDateOnly (@.pInputDate datetime)
returns datetime
as
begin
return dateadd(day, datediff(day, 0, getdate()), 0)
end|||thanks alot for the advise. I thought about stored procedure, but then like you mentioned I can't use it in a SELECT which was my whole goal. Back to the drawing board :-)

Randy

Converting the value to data format

Hello Everyone,

Please guide me in converting the value to date format.

from source i'm getting the value (which is acchally a data value) '20070730'.

I need this value to be in date format '2007/07/30'

Please help me in getting it done.

thank you

Hi

Select Cast('20070730' as datetime)

Beware of collation configured in your SQL instance and your database

Jean-Pierre

|||

Sorry! I had posted my question in the wrong path.

i wanted this to be done thru Integration services.

Converting the string value to data format

Hello Everyone,

Please guide me in converting the value to date format.

from source i'm getting the value (which is acchally a data value) '20070730'.

I need this value to be in date format '2007/07/30'

Please help me in getting it done.

thank you

Hi

Code Snippet

select cast('20070730' as datetime)

Note : beware of collation used in your SQL instance or your database.

--

Jean-Pierre

|||

THANK YOU FOR YOUR REPLY.

bUT MY SOURCE IS FALAT FILE

|||

HI, you van use a derived column with the following expression:

(DT_DBTIMESTAMP)(SUBSTRING(Column,1,4) + "-" + SUBSTRING(Column,5,2) + "-" + SUBSTRING(Column,7,2))

HTH,

Ccote

Tuesday, February 14, 2012

Converting text to date

I have a field that stores a date as text (121205). I need to convert this field to a date, but since it is text, I cannot figure out how to do it. Any ideas? Thanks! :Dwhich database? informix? sybase? db2? access? firebird? oracle? mysql? sql server? postgresql?|||SQL Server|||Moving this thread to Microsoft SQL Server forum, but I'd use:SELECT t, Convert(DATETIME, Stuff(Stuff(t, 5, 0, '/'), 3, 0, '/'))
FROM (SELECT '121205' AS t UNION SELECT '111105' UNION SELECT '101005') AS z
-PatP|||As you can tell, Pat likes to STUFF things...

CREATE PROC mySproc99 @.x text
AS
SELECT CONVERT(datetime, CONVERT(varchar(25),@.x))
GO

EXEC mySproc99 '121205'
GO

DROP PROC mySproc99
GO

So who's to say it's not 2012?|||Brett is correct, you don't need the slashes in the US, and maybe not in the UK either... They assume a string of digits are MMDDYY. As far as I know, the slashes work in any locale.

-PatP

Converting table date

I am trying to to take data from a table where the Row data contains 24
columns representing hors 12 midnight to 11 PM see (sample below) into a
table that puts 1 hour per row?
Initial table
Name Date 12Min 1Min 2Min 3Min … 11Min
Mickey 12/2/05 625.4 153.2 84635…
Convbert to another table
Name Date Min
Mickey 12/2/05 00:00:00 625.4
Mickey 12/2/05 01:00:00 153.2
Mickey 12/2/05 02:00:00 84635Use unions.
e.g. (note: while you don't need to dateadd(hour,0,[Date]), but this
will work if the datatype is datetime or varchar)
select Name, dateadd(hour, 0, [Date]) as [Date], 12Min as Min from yourtable
union all
select Name, dateadd(hour, 1, [Date]) as [Date], 1Min as Min from yourtable
union all
...
union all
select Name, dateadd(hour, 11, [Date]) as [Date], 11Min as Min from
yourtable
Jim Abel wrote:
> I am trying to to take data from a table where the Row data contains 24
> columns representing hors 12 midnight to 11 PM see (sample below) into a
> table that puts 1 hour per row?
> Initial table
> Name Date 12Min 1Min 2Min 3Min … 11Min
> Mickey 12/2/05 625.4 153.2 84635…
> Convbert to another table
> Name Date Min
> Mickey 12/2/05 00:00:00 625.4
> Mickey 12/2/05 01:00:00 153.2
> Mickey 12/2/05 02:00:00 84635
>

Converting strings to dates

Hi,

I have a varchar column with mixed date formats, some are dd-mm-yyyy and others are mmm dd yyyy hh:mmAP, these latter having been generated automatically by SQL when I changed the column datatype from datetime to varchar.

I would like to run an update script to pattern match the latter and change to the former.

I've been trying something along the lines of

update dwsubmit set authoreddate = (select day(authoreddate))+'-'+(select month(authoreddate))+'-'+(select year(authoreddate)) where id = 841

to try and get the format conversion correct, but this is obviously not correct. I have tried a few combinations, but have had no joy. Any ideas?

Thanks, Matt.I understand ur pain man...but u r doin it wrongly. Try this:

update dwsubmit
set authoreddate = (select datepart(authoreddate,dd))+'-'+(select datepart(authoreddate,mm))+'-'+(select datepart(authoreddate,yy))
where id = 841

op it works for u...av fun!|||sorry i mixed it up

update dwsubmit
set authoreddate = (select datepart(dd,authoreddate))+'-'+(select datepart(mm,authoreddate))+'-'+(select datepart(yy,authoreddate))
where id = 841

it should be ds way...sorry about dat...|||Thanks for that - I tried something similar, but SQL is actually adding the values up to come up with 2022 (04 + 12 + 2006). I have no idea what it is doing with the '-' characters. I then tried casting each part to char, but it ignores that too!|||i op u tried d 2nd version not d first...ol d same

try ds...

update dwsubmit
set authoreddate = select datepart(dd,authoreddate) + '-' + select datepart(mm,authoreddate) + '-' + select datepart(yy,authoreddate)
where id = 841|||Using what you gave me, I got to the following:

update dwsubmit
set authoreddate = cast((select datepart(dd,authoreddate)) as char(2))+'-'+cast((select datepart(mm,authoreddate)) as char(2))+'-'+cast((select datepart(yy,authoreddate)) as char(4))
where id = 841

Which gives me what I want unless there is only a single digit for the month or day, in which case I get something like 4 -12-2006 which should actually be 04-12-2006.

I'm sure the convert function is a better way of doing this, but I can't figure it out!

Thanks,
Matt.

Converting string to datetime

Hi

What's wrong about

SELECT SUM(CASE WHEN [PO Date] BETWEEN CONVERT(Datetime, @.FY + '/04/01')
AND CONVERT(Datetime, @.FY -1 + '/03/31') THEN Quantity ELSE 0 END) AS Expr1,
[Item No_]
FROM table A

It looks like you are trying to use the aggregate function sum() and the [item no_] column is not in an aggregate function or group by clause

|||

here it is,

Code Snippet

SELECT

SUM(CASE WHEN [PO Date] BETWEEN CONVERT(Datetime, @.FY + '/04/01')

AND CONVERT(Datetime, @.FY -1 + '/03/31') THEN Quantity ELSE 0 END) AS Expr1,

[Item No_]

FROM table A

Group By

[Item No_]

|||

Still can't! It show error massage" wrong parameter".

|||

Please provide the entire procedure code and the error message in its entirity.|||

Hi

I use this query on reporting service. After perview will show "Conversion failed when converting to varchar value"/04/01" to date type int.

|||

You are attempting to concatenate the varchar value '/04/01' to the integer value @.FY.

You need to first cast the variable @.FY as a char()/varchar().

However, this could be avoided IF you used an actual datetime value for the fiscal year instead an integer value. This may be an excellent opportunity to finally explore using the 'Calendar' table you've most likely heard about before. I recommend reviewing this article to see if there is utility in the concept for you.

(From this example, I suspect that there are other places in your code where you are attempting to handle 'date' issues in 'creative' and non-functional methods.)

Datetime -Calendar Table
http://www.aspfaq.com/show.asp?id=2519

|||

Hai,

As Arnie said, you need to first convert @.FY value to varchar type.

And, also, in your query, first date in Between is > second date which always returns the Expr1 to 0.

you can try this, sample, query:

DECLARE @.FY int

DECLARE @.TableA Table([PODate] datetime, [ItemNo_] int, Quantity int)

INSERT INTO @.TableA([PODate], [ItemNo_], Quantity) VALUES('2007/03/01',1, 200)

INSERT INTO @.TableA([PODate], [ItemNo_], Quantity) VALUES('2007/03/03',1, 100)

INSERT INTO @.TableA([PODate], [ItemNo_], Quantity) VALUES('2007/03/05',1, 50)

INSERT INTO @.TableA([PODate], [ItemNo_], Quantity) VALUES('2007/03/10',2, 30)

INSERT INTO @.TableA([PODate], [ItemNo_], Quantity) VALUES('2007/03/22',2, 40)

INSERT INTO @.TableA([PODate], [ItemNo_], Quantity) VALUES('2007/04/01',3, 60)

SET @.FY = 2007

SELECT

SUM(CASE WHEN [PODate] BETWEEN CONVERT(Datetime, CONVERT(VarChar(4),(@.FY-1)) + '/03/31') AND

CONVERT(Datetime, CONVERT(VarChar(4),@.FY) + '/04/01')

THEN Quantity ELSE 0

END) AS Expr1,

[ItemNo_]

FROM @.TableA

GROUP BY [ItemNo_]

Hope this will work, Please clarify If'm wrong.

Regards,

Y.Kiran Kumar.

Converting String to Date in Report Expressions

Hello,

I am running a report in RS 2005 and as an expression I have something like that:

=DateDiff("YYYY", NOW(), CDATE("2001"))

Unfortunately, I am getting message:

Conversion from string "2001" to type 'Date' is not valid.

Is there a way to fix it?

Thanks!

The CDATE function wants a valid date format passed to it and not just the year. It would work if you specified something like "1/1/2001" or "Jan 1, 2006". However, it appears all you're trying to do is find the difference between the current year and some specified year. If that's the case, I would suggest using the following expression instead:

=Year(Now()) - 2001

or if the specified year is a string value:

=Year(Now()) - CInt("2001")

Sincerely,

Micheal

|||

Greate advice!

Thanks for your help!

converting string to date

Hello,

I try to convert a pseudo datetime string into a date. In Oracle I can do
to_date( MyDate, 'yyyymmddhh24miss' ); how I can do this with MS SQL ?

thanks and regards
MarkSee CONVERT() in Books Online - it supports a number of different
formats, although not the exact one you've mentioned above. You might
need to look at modifying the string before using CONVERT() - see
"String Functions" in Books Online, or you could also consider doing
that in your client application.

Simon|||On Fri, 12 Aug 2005 14:17:57 +0200, Mark wrote:

>Hello,
>I try to convert a pseudo datetime string into a date. In Oracle I can do
>to_date( MyDate, 'yyyymmddhh24miss' ); how I can do this with MS SQL ?
>thanks and regards
>Mark

Hi Mark,

The easiest way is to use string functions to convert your date to the
unambiguous ISO-standard yyyy-mm-ddThh:mm:ss format, then cast to
datetime:

DECLARE @.DateString char(14)
SET @.DateString = '20050812204332'
SELECT CAST(SUBSTRING(@.DateString, 1, 4) + '-'
+ SUBSTRING(@.DateString, 5, 2) + '-'
+ SUBSTRING(@.DateString, 7, 2) + 'T'
+ SUBSTRING(@.DateString, 9, 2) + ':'
+ SUBSTRING(@.DateString, 11, 2) + ':'
+ SUBSTRING(@.DateString, 13, 2) AS datetime)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Converting Sql7 to 2000 version

Can anyone tell where i can find any guide to prevent big error!! My problems
are date and string. When using datetime fields, before i used [yyyy-mm-dd]
format, now its no longer available!!! How cai i do?!!?! Must i covert all
stored procedure or code? Wich problems can i have with the new string limit?
Thanx all!!
Marko
Hi
Have you looked at CAST and CONVERT. Formatting a string as you want is is
still there.
How are you trying to use the data?
Regards
Mike
"Marko" wrote:

> Can anyone tell where i can find any guide to prevent big error!! My problems
> are date and string. When using datetime fields, before i used [yyyy-mm-dd]
> format, now its no longer available!!! How cai i do?!!?! Must i covert all
> stored procedure or code? Wich problems can i have with the new string limit?
> Thanx all!!
> Marko
|||Thanx, but all my Stored Procedure i use CONVERT to obtain 120th format,
yyyy-mm-dd.
With 2000 version this is not good, and i must correct all the procedure
with yyyymmdd: is it correct?
This is a problem for me because i must to correct many procedures and then
i must tu correct all the procedure call from ado Connection; for example
cn.execute ("MyProc 'yyyy-mm-dd'") must become cn.execute ("MyProc
'yyyymmdd'")
Can you help me?
Again , Thanx !!
Mark
"Mike Epprecht (SQL MVP)" wrote:
[vbcol=seagreen]
> Hi
> Have you looked at CAST and CONVERT. Formatting a string as you want is is
> still there.
> How are you trying to use the data?
> Regards
> Mike
> "Marko" wrote:

Converting Sql7 to 2000 version

Can anyone tell where i can find any guide to prevent big error!! My problem
s
are date and string. When using datetime fields, before i used [yyyy-mm-
dd]
format, now its no longer available!!! How cai i do'!!?! Must i covert all
stored procedure or code? Wich problems can i have with the new string limit
?
Thanx all!!
MarkoHi
Have you looked at CAST and CONVERT. Formatting a string as you want is is
still there.
How are you trying to use the data?
Regards
Mike
"Marko" wrote:

> Can anyone tell where i can find any guide to prevent big error!! My probl
ems
> are date and string. When using datetime fields, before i used [yyyy-m
m-dd]
> format, now its no longer available!!! How cai i do'!!?! Must i covert a
ll
> stored procedure or code? Wich problems can i have with the new string lim
it?
> Thanx all!!
> Marko|||Thanx, but all my Stored Procedure i use CONVERT to obtain 120th format,
yyyy-mm-dd.
With 2000 version this is not good, and i must correct all the procedure
with yyyymmdd: is it correct'
This is a problem for me because i must to correct many procedures and then
i must tu correct all the procedure call from ado Connection; for example
cn.execute ("MyProc 'yyyy-mm-dd'") must become cn.execute ("MyProc
'yyyymmdd'")
Can you help me?
Again , Thanx !!
Mark
"Mike Epprecht (SQL MVP)" wrote:
[vbcol=seagreen]
> Hi
> Have you looked at CAST and CONVERT. Formatting a string as you want is is
> still there.
> How are you trying to use the data?
> Regards
> Mike
> "Marko" wrote:
>

Converting Sql7 to 2000 version

Can anyone tell where i can find any guide to prevent big error!! My problems
are date and string. When using datetime fields, before i used [yyyy-mm-dd]
format, now its no longer available!!! How cai i do'!!?! Must i covert all
stored procedure or code? Wich problems can i have with the new string limit?
Thanx all!!
MarkoHi
Have you looked at CAST and CONVERT. Formatting a string as you want is is
still there.
How are you trying to use the data?
Regards
Mike
"Marko" wrote:
> Can anyone tell where i can find any guide to prevent big error!! My problems
> are date and string. When using datetime fields, before i used [yyyy-mm-dd]
> format, now its no longer available!!! How cai i do'!!?! Must i covert all
> stored procedure or code? Wich problems can i have with the new string limit?
> Thanx all!!
> Marko|||Thanx, but all my Stored Procedure i use CONVERT to obtain 120th format,
yyyy-mm-dd.
With 2000 version this is not good, and i must correct all the procedure
with yyyymmdd: is it correct'
This is a problem for me because i must to correct many procedures and then
i must tu correct all the procedure call from ado Connection; for example
cn.execute ("MyProc 'yyyy-mm-dd'") must become cn.execute ("MyProc
'yyyymmdd'")
Can you help me?
Again , Thanx !!
Mark
"Mike Epprecht (SQL MVP)" wrote:
> Hi
> Have you looked at CAST and CONVERT. Formatting a string as you want is is
> still there.
> How are you trying to use the data?
> Regards
> Mike
> "Marko" wrote:
> > Can anyone tell where i can find any guide to prevent big error!! My problems
> > are date and string. When using datetime fields, before i used [yyyy-mm-dd]
> > format, now its no longer available!!! How cai i do'!!?! Must i covert all
> > stored procedure or code? Wich problems can i have with the new string limit?
> > Thanx all!!
> > Marko