Last post Jul 07, 2014 08:53 AM by nvielbig
Jul 07, 2014 08:42 AM|nvielbig|LINK
I am attempting to format a DateTime variable before returning it by using the AppendFormat method in StringBuilder, but I am not seeming to be using it correctly.
StringBuilder stringBuilder = new StringBuilder();stringBuilder.AppendFormat("MM/dd/yyyy", this.LastRunDate);
However, the output result is just displaying my format to use as text on my webpage.
LastRunDate is of type nullable DateTime.
Thanks for any pointers.
Jul 07, 2014 08:46 AM|nvielbig|LINK
As always, the best results on google come after the question is posted...
This did the trick: http://stackoverflow.com/a/1833070/2654498
Jul 07, 2014 08:48 AM|Rion Williams|LINK
If you are dealing with a nullable DateTime object, you'll likely want to check and ensure that it is null when determining what to insert :
// This will store either a string version of your nullable DateTime or "None" if it was null
var yourInsertString = YourNullableDateTime.HasValue ? YourNullableDateTime.Value.ToString() : "None";
Jul 07, 2014 08:53 AM|nvielbig|LINK
I stripped unrelated code from my question for clarity reasons, but I actually already was doing null check for this :-)
Thanks for the lookout.