can someone help me to convert the following PL SQL code into it's MSSQL equivalent? Thanks in advance.
return to_date(l_date_time, 'rrrrdddhh24miss');
can someone help me to convert the following PL SQL code into it's MSSQL equivalent? Thanks in advance.
return to_date(l_date_time, 'rrrrdddhh24miss');
MS SQL Server 2012 Schema Setup:
CREATE TABLE Table1
([l_date_time] varchar(25))
;
INSERT INTO Table1
([l_date_time])
VALUES
('1-5-13 1:02:03 PM'),
('9-4-73 9:10:11 AM')
;
Query 1:
select convert(varchar(4), datepart(yyyy,l_date_time)) +
right('00' + convert(varchar(3), datepart(dy,l_date_time)),3) +
right('0' + convert(varchar(2), datepart(hh,l_date_time)),2) +
right('0' + convert(varchar(2), datepart(mi,l_date_time)),2) +
right('0' + convert(varchar(2), datepart(ss,l_date_time)),2)
from Table1
| COLUMN_0 |
|---------------|
| 2013005130203 |
| 1973247091011 |
Also, take this in consideration :
"Microsoft SQL Server uses 2049 as the cutoff year for interpreting dates; OLE Automation objects use 2030. You can use the two digit year cutoff option to provide consistency in date values between SQL Server and client applications. However, to avoid ambiguity with dates, use four-digit years in your data."