SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 datetime
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

410 Posts

Posted - 10/22/2013 :  22:38:35  Show Profile  Reply with Quote
i would like to add in column name on first row. i did this as below:

select * from (
select convert(nvarchar,'CaseDate')CaseDate
union all
select convert(nvarchar,dateadd(hour,8,CreatedOn)) CaseDate from tableA
)a

and i get this:

CaseDate
CaseDate
Oct 22 2013 1:00PM

how can i get the date like this?

2013-10-22 13:00:00.000

peace
Constraint Violating Yak Guru

410 Posts

Posted - 10/22/2013 :  22:49:13  Show Profile  Reply with Quote
i got it.

I used this:
CONVERT(NVARCHAR, date, 121)
Go to Top of Page

peace
Constraint Violating Yak Guru

410 Posts

Posted - 10/22/2013 :  22:55:43  Show Profile  Reply with Quote
what if i want to convert to dateadd hour 8?

select dateadd(hour,8,casedate)casedate from (
select CONVERT(NVARCHAR, 'CaseDate', 121)
union all
select CONVERT(NVARCHAR, CaseDate, 121) CaseDate from tableA
)a

i get this error:

Conversion failed when converting date and/or time from character string.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17650 Posts

Posted - 10/23/2013 :  00:28:19  Show Profile  Reply with Quote
select 'CaseDate' as CaseDate
union all
select CONVERT(NVARCHAR(10), dateadd(hour, 8, CaseDate), 121) CaseDate from tableA



KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 10/23/2013 :  01:30:47  Show Profile  Reply with Quote
quote:
Originally posted by peace

what if i want to convert to dateadd hour 8?

select dateadd(hour,8,casedate)casedate from (
select CONVERT(NVARCHAR, 'CaseDate', 121)
union all
select CONVERT(NVARCHAR, CaseDate, 121) CaseDate from tableA
)a

i get this error:

Conversion failed when converting date and/or time from character string.


See this

http://visakhm.blogspot.in/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000