I have a column in a DB2/400 table as TIMESTAMP type.

I am filtering like this:

select scmach,count(*) from f55br001 where sctrdj >='2013-08-30 00:00:00' group by scmach order by scmach

In a simple ASP.NET Web Pages app i am using it like this:

var lastUpdate = db.QuerySingle("select max(sccrdj) as LASTUPDATE from PRODDTA.F55BR001 where SCTRDJ >= '" + dateParam + "'");
    var maxDate = lastUpdate.LASTUPDATE;

and then:

<h3>
    Last update: @maxDate
</h3>

in the web page its being printed as:

2013-08-31-14.01.09.000000

I cant find any way to convert it in a proper datetime field.

GetType() says its a string when it comes from db and DateTime.Parse doesnt work either

EDIT:

The only way i found is using ParseExact. Is this the proper way?

string dateFormat = "yyyy-MM-dd-HH.mm.ss.FFFFFF";
    var maxDate = DateTime.ParseExact(lastUpdate.LASTUPDATE,dateFormat, CultureInfo.InvariantCulture);
有帮助吗?

解决方案

The only way I found is using ParseExact.

string dateFormat = "yyyy-MM-dd-HH.mm.ss.FFFFFF";
var maxDate = DateTime.ParseExact(lastUpdate.LASTUPDATE,dateFormat, 
                                               CultureInfo.InvariantCulture);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top