sql date

May 21, 2009 at 4:04 PM

Is there a sql way to convert data "01/04/2008 1430" to appear as 2008/04/01?

May 21, 2009 at 6:24 PM

You could do that in a converter routine or in the SQL to produced the date you could extract the data from the date. Look closely at what you asked for. Your result is Year/day/month. The SQL would look like this:

 

 

 

 

 

 

<font size="3" color="#0000ff"><font size="3" color="#0000ff">

DECLARE

</font></font><font size="3" color="#0000ff">

 

</font>

@SomeDate DATETIME = GETDATE();

<font size="3" color="#0000ff"><font size="3" color="#0000ff">

SELECT

</font></font>
<font size="3" color="#0000ff">

 

</font>

CAST(YEAR(@SomeDate) AS CHAR(4))

+ '/'

<font size="3">

 

</font>

 

+ RIGHT(('0' + CAST(DAY(@SomeDate) AS VARCHAR(2))), 2)

<font size="3">

 

</font>

 

+ '/'

<font size="3">

 

</font>

 

+ RIGHT(('0' + CAST(MONTH(@SomeDate) AS VARCHAR(2))), 2);

May 21, 2009 at 6:44 PM

I ended up doing the following:

 

Mid(left(Job.LastModified, 10), 5, 8) & '/' &  Mid(left(Job.LastModified, 10), 3, 2) & '/' & Mid(left(Job.LastModified, 10), 1, 2) AS Dates