Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I require datetime format as 'YYYY-MM-DD HH:MM:SS' from sql server data table where I've stored date, time in separate columns.
 
I tried to convert in code behind
 
DateTime.ParseExact(ds.tables(0).rows(0).item(0).ToString & " " & ds.tables(0).rows(0).item(1), "YYYY-MM-DD HH:MM:SS", CultureInfo.InvariantCulture)
 
Error: String was not recognized as a valid DateTime.
 
I also tried to convert and select in sql server query
select convert(datetime, DateColumnName + TimeColumnName, 120) as NewDatetime, from TableName
 
Error: Operand data type date is invalid for add operator.
 

But I get errors
 
Help me to resolve it.
 
Thanks
Posted 21-Nov-12 22:37pm
Edited 21-Nov-12 22:39pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try something like below :
SELECT CONVERT(VARCHAR(10), GETDATE(), 120) + ' ' + CONVERT(VARCHAR, GETDATE(),108) AS NEWDATETIME
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try
SELECT replace(convert(varchar, DateColumnName, 111), '/', '-') + ' ' + convert(varchar, TimeColumnName,108) AS NewDatetime FROM TableName
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 457
1 OriginalGriff 430
2 Shai Vashdi 240
3 Emre Ataseven 165
4 Peter Leow 146
0 Sergey Alexandrovich Kryukov 8,944
1 OriginalGriff 5,280
2 Peter Leow 3,985
3 Maciej Los 3,535
4 Abhinav S 3,218


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid