DateTime format{ts 'YYYY-MM-DD '} used with SQL

I am using instances of DateTime within my application
and i need their values to be used as selection criteria in an SQL
select clause.

So i need them to return a literal string representation of themselves
in the following format

'{ts '1990-01-01 00:00:00'}'

Where the date can be any valid date as contained in the DataTime
instance.

How can i get them to do this

I



Answer this question

DateTime format{ts 'YYYY-MM-DD '} used with SQL

  • Bjornar

    Thanks Martin, that neally works, i did not know you could do that with the format string.

    Except that the it requires the {ts' '} characters as in

    {ts '2006-03-28 13:06:50'}

    else i get SQL error.

    When i include these characters it returns a strange string like the following:

    {A0 yyyy-MM-dd hh:mm:ss}

    So the {} have been included, but the ' have been removed and the ts has been replaced by A0

    How can i get it to leave these characters in


  • JEP8979

    I will have to try different formats.

    I assumed the {ts ''} part needs to be present - maybe things have changed

    I noticed the DataTIme return a universal sortable time - maybe it now needs to be in this format or something.

    The target column on the database is DATE.

    Things like this can take so long to get to the bottom of. Its fine when you have done it once.

    Should just be a clear mapping from the old to the new.


  • dave_cw3w

    Sorry! No idea!

  • excelthoughts

    Oh man! Just zhink a little bit.

    When you have the date formatted correctly. Isn't it possible to concatenate the rest to it



  • David Olix - MSFT

    Yes Martin ur right.

    I used a StringBuilder to do the rest.

    My problem now is that the System.Data.OracleClient does not like it

    Im getting Invalid Character -

    its the data-format string - ok if i exclude this part.

    SELECT * from members WHERE effective_date <= {ts '2006-03-03 12:00:00'}

    If i run this via my old unmanaged app with ODBC drivers etc - its fine!

    Any ideas on this one would be greatly appreciated. Im really stuck on this one.


  • FloridaAviator

    System.DateTime.ToString with format "yyyy-MM-dd hh:mm:ss"

     



  • DateTime format{ts 'YYYY-MM-DD '} used with SQL