Solved

Like Oracle TO_DATE SQL function

Posted on 2004-08-16
2
1,545 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
Comment Utility
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
Comment Utility
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

772 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

11 Experts available now in Live!

Get 1:1 Help Now