Solved

Like Oracle TO_DATE SQL function

Posted on 2004-08-16
2
1,555 Views
Last Modified: 2008-03-10
I would like to know if MSQL has a function
like Oracle TO_DATE SQL function.

TO_DATE converts a string to a DATE value.

for example:

to_date('1998/05/31:12:00:00AM', 'yyyy/mm/dd:hh:mi:ssam'));


Thanks
0
Comment
Question by:vcarballo
2 Comments
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 250 total points
ID: 11815316
With less flexibility, yes.  You have to use CAST or CONVERT.  CAST works if the format is a "standard" format that SQL automatically recognizes, for example:

CAST('1998-05-31 12:00:00AM' AS DATETIME)

Convert is necessary for a "non-standard" format, although no format corresponds to "yyyy/mm/dd hh:mm:ssam'.  That is what is less flexible; you ultimately have to use a format that SQL will recognize.

See Books Online for more details on CAST and CONVERT.
0
 

Author Comment

by:vcarballo
ID: 11857135
Thanks a lot

This is my way:

convert(datetime, convert(char(2), DAY(getdate())) + '/' +
                          convert(char(2), MONTH(getdate())) + '/' +
                          convert(char(4), YEAR(getdate())), 103)
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

895 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

12 Experts available now in Live!

Get 1:1 Help Now