SmartDate to DB2 Conversion

SmartDate to DB2 Conversion

Old forum URL: forums.lhotka.net/forums/t/1085.aspx


A.Finney posted on Thursday, August 31, 2006

I'm having an issue converting dates. The following is the sequence of events.

1. Retrieve the timestamp from DB2 using a SafeDataReader,
2. Assign it to a variable,
3. Modify the value,
4. Save it back to DB2 using a ODBC connection object as a SQL string.

My problem is this... DB2 expects the date to be formatted as:

('2002-10-20-12.00.00.000000')

My question is simple. How do I get it formatted properly?

This is as close as I have gotten:

SmartDate MyDate = SmartDate.Parse(DateTime.Now.ToLongTimeString()).FormatString ("yyyy-MM-ddTHH:mm:ss");

Console.WriteLine(MyDate);

Any help would be greatly appreciated.

 

Brian Criswell replied on Thursday, August 31, 2006

You can set the text output format used by the SmartDate by setting the format string property.

So your example would look like:

SmartDate myDate = new SmartDate(DateTime.Now);
myDate.FormatString = "yyyy-MM-ddTHH:mm:ss";
Console.WriteLine(myDate);

or something to that effect.

A.Finney replied on Thursday, August 31, 2006

Very Close!  Close enough for me to figure it out.

public static string db2TimeStamp(SmartDate dt)
{
//For Testing Use the current date time
//dt = SmartDate.Parse(DateTime.Now.ToString(), true);
//otherwise....
dt.FormatString = "yyyy-MM-dd-HH.mm.ss";
string x = "TimeStamp('" + dt + "')";
return x;
}

THANKS ! Big Smile [:D]

 

Copyright (c) Marimer LLC