Skip to content

Convert Date time format

srujana thallam

Asked Apr 16, 2014, 5:35 AM EDT2 answers
Share
LinkedInX
Hi
I have a Db2 data base in db2 the date and time stored including millisec.I want to get the data from DotNet C#. For comparing I have a data without milli sec.so i want to remove the millisec dta in db and compare .
This is my C# Query.
"SELECT " + "'(TIMESTAMP_FORMAT(StartDate,'YYYY-MM-DD HH24:MI:SS'))'"+ " FROM TableName where " + FirstName+ " = '" + fName + "'";
Can any one guide to get the result without Millisec.
Thanks

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi,
    Try this

    Replace your 
    Query ---------> (TIMESTAMP_FORMAT(StartDate,'YYYY-MM-DD HH24:MI:SS'))

    and write like this

    convert(datetime, convert(char(19), StartDate, 120))

    OR

    dateadd(millisecond, -datepart(millisecond, StartDate), StartDate)
    0
  • 0
    Hi Sachin,

    Thanks for your post.But again it will shows error,the query will not run.
    I am trying run it in DB2
    0