Skip to content

Instantly share code, notes, and snippets.

@DapperJohn
Created June 30, 2015 14:45
Show Gist options
  • Save DapperJohn/a7f305a4fd76b3d5dc2e to your computer and use it in GitHub Desktop.
Save DapperJohn/a7f305a4fd76b3d5dc2e to your computer and use it in GitHub Desktop.
///////////////////////////////////////
//if datetime is null return min value
///////////////////////////////////////
var tradeDate = (r["Trade Date"]).ToString();
var settlementDate = (r["Stl Date"]).ToString();
if ((r["Stl Date"]) != null){
tradeDate = Convert.ToDateTime(r["Trade Date"]).ToString("MM/dd/yyyy");
}
else tradeDate = DateTime.MinValue.ToString();
if ((r["Stl Date"]) != null){
settlementDate = Convert.ToDateTime(r["Stl Date"]).ToString("MM/dd/yyyy");
}
else settlementDate = DateTime.MinValue.ToString();
//////////////////////////////////////////////
//can be easily written like this instead
//////////////////////////////////////////////
var tradeDate = (r["Stl Date"]) != null ? Convert.ToDateTime(r["Trade Date"]).ToString("MM/dd/yyyy") : DateTime.MinValue.ToString();
var settlementDate = (r["Stl Date"]) != null ? Convert.ToDateTime(r["Stl Date"]).ToString("MM/dd/yyyy") : DateTime.MinValue.ToString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment