TO_Date?

Apr 8, 2006

Ok i'm trying to figure out how to properlyuse the to_date function. Ive read about it in my book and tried looking up some examples of it online... but im still confused on how to use it in my situation.


SELECT TITLE,INITCAP(PUBDATE(TO_DATE(PUBDATE,'Month DD, YYYY'))) FROM BOOKS;

That was my last attempt. Im just trying to get the title and the date for all of the books in the books table. the first letter of the book is supposed tobe capitalized, so i used initcap but then im supposed to put them month in Month DD, YYYY format. I looked it up, seems To_date is my answer but all of the examples seem to confused me. They are all being used along with where functions and I think its confusing me. Can anyone help explain how to use it in this situation?

View 5 Replies


ADVERTISEMENT

TO_DATE Conversion

May 2, 2008

Hello,

I am very new to SQL and was handed some Oracle code to put into a SQL Server 2005 db. A few errors come up, but the one I'm having the hardest time converting is:

INSERT INTO Reservations VALUES (102, TO_DATE('10/14/03', 'MM/DD/YY'),
22, TO_DATE('10/10/03', 'MM/DD/YY'));

and the error message that accompanies it upon parsing is:

Msg 195, Level 15, State 10, Line 86
'TO_DATE' is not a recognized built-in function name.

Any help converting this to SQL Server's liking would be greatly appreciated.

Thanks!

Fry

View 3 Replies View Related

To_date Funtion YYYY-DD-MM

Jan 30, 2008

Hi All:
We have a database date column in this format: 1/27/2008 1:20:00 AM and need a date or time function to cast local JVM time into the above format.

Suggest me the best options.
1. To go for a more comfortable date format in the database itself or
2. To have an appropriate conversion in my code.( I am not feeling good about the suffix AM/PM in the date column!)

Thanks.

View 20 Replies View Related

Create A TO_DATE Function For Use In SQLServer 2005

Feb 28, 2008

Hi ,

I 'm working with visual studio 2005 and I have created an SQLServer Project.
I'm using the CLR functionality which comes with SQLserver 2005. This means that I can write VB.nEt code and use it inside Sqlserver 2005.So far so good.
I am now inside the .NET
I have created a Function(must remind you that I have created an SQLserver Project) which takes two string arguments. The date value in a string format and the string format.

In Our case the function returns a string.It will return a datetime although.
So we have

Dim Datetime_Val As DateTime = Nothing
Dim Date_Val As Date = Nothing
Dim StrTemp As String = ""
Dim StrDateTemp As String = Nothing
Dim StrTimeTemp As String = Nothing
Dim ls_return As String = Nothing
Dim lindexof As Integer
Dim Counter As Integer = 0

lindexof = 0
Select Case StrFormat
Case "DD-MM-YYYY HH24:MIS"
For Counter = 1 To 2
lindexof = StrDate.IndexOf("-", lindexof + 1)
Next
lindexof += 5

StrDateTemp = StrDate.Substring(0, lindexof).Trim
StrTimeTemp = StrDate.Substring(StrDateTemp.Length, StrDate.Length - StrDateTemp.Length).Trim
ls_return = StrDateTemp & " " & StrTimeTemp

End Select

The above is a simple code. As you can see I'm trying to convert the TO_DATE function ,which work with ORACLE, to make it work with SQLServer 2005.
I've been trying unsuccessfully to combine the variables StrDateTemp and StrTimeTemp into a datetime value. I used the following code but nothing

Datetime_Val = CDate(StrDateTemp & " " & StrTimeTemp)
Didn't work

Datetime_Val = Convert.ToDateTime(StrDateTemp & " " & StrTimeTemp)
Didn't work

Datetime_Val = DateTime.Parse(StrDateTemp & " " & StrTimeTemp)
Didn't work

Inside SQlServer I used this SQL statement

Select dbo.TO_DATE('31-12-1990 00:26:46','DD-MM-YYYY HH24:MIS')

But I am receiveing an error. I want to avoid changing all of my applications with a specific format.This sql statement without the dbo prefix I'm using in Oracle. I want to keep the format of the SQL and let VB.NET do the parsing for me. It is easier for me to put in my SQLs the dbo infront rather changing the complete SQL.
I have two questions . How am I going to create a TO_DATE function which Oracle uses and write something similar in SQLserver ?
And If I cannot do that how am I going to get the database 's datetime format and create with VB.NET the Datetime value from the two variables ?

My problem I believe is quite complex. I would be mostly appreciated if you could help me on this.

Thank you

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved