SmartDate Question: Appears to be truncating time portion.

SmartDate Question: Appears to be truncating time portion.

Old forum URL:

skeeler posted on Friday, May 03, 2013

I have a ReadOnlyList and a BusinessBase class that contains Event information something like this.



        public static readonly PropertyInfo<SmartDate> StartProperty = RegisterProperty<SmartDate>(p => p.Start, "Start");

        public string Start


            get { return GetPropertyConvert<SmartDate, String>(StartProperty); }

            set { SetPropertyConvert<SmartDate, String>(StartProperty, value); }


        public static readonly PropertyInfo<SmartDate> EndProperty = RegisterProperty<SmartDate>(p => p.End, "End");

        public string End


            get { return GetPropertyConvert<SmartDate, String>(EndProperty); }

            set { SetPropertyConvert<SmartDate, String>(EndProperty, value); }


When the entity is Created with a value that contains both a date and time via the BusinessBase object the time is stored correctly in the database.
When the application retrieves the objects & values via SafeDataReader and into my ReadOnlyList into the Mvc4 application it seems to have truncated the time portion of the date.
What am I doing wrong? Any suggestions?



tiago replied on Friday, May 03, 2013

Hi skeeler,

I also noticed SmartDate just shows the date. After all it's SmartDate and not SmartDateTime

For simple auditing purposes - i.e. CreatedOn / ChangedOn - I use DateTime and set the same value on both properties when the object is created. As these properties can never be null I don't need any "smartness" here.

skeeler replied on Friday, May 03, 2013

They are going to be a nullable datetime. I guess I'll have to just do the ladder.

Thanks for the help.

JonnyBee replied on Saturday, May 04, 2013


SmartDate supports format strings and the default format is"d".
Se also Standard Date and Time Format strings

Try  this code:

      var sd = new SmartDate();
      Debug.Print("default format: {0}", sd.FormatString);
      sd.FormatString = "g";
      Debug.Print("new format: {0}", sd.FormatString);
      sd.Text = DateTime.Now.ToString("g");

Gives this result on my culture:

default format: d
new format: g
04.05.2013 12:08
04.05.2013 12:08

when the datetime format is changed to "g" = General date/time pattern (short time).

Troncho replied on Tuesday, June 09, 2015

Hi Jonny. I have this special case where I need to select Date + Time as a property for user input.

On my BusinessBase constructed class, I declare the property like this:

private static PropertyInfo<SmartDate> StartDateTimeProperty = RegisterProperty<SmartDate>(c => c.StartDateTime, "Start Date & Time"new SmartDate(DateTime.Now));
public string StartDateTime
		var tempSD = GetProperty(StartDateTimeProperty);
		tempSD.FormatString = "G";
		string retValue = tempSD.Text;
		return retValue;
		//return GetPropertyConvert<SmartDate, string>(StartDateTimeProperty); 
	set { SetPropertyConvert<SmartDatestring>(StartDateTimeProperty, value); }

This is working fine but I think there may be a better way consisting of somehow being able to assign [StartDateTimeProperty.FormatString] without deriving a new [struct] from SmartDate. It would be more elegant. Is there any way of doing this?



JonnyBee replied on Wednesday, June 10, 2015


You can specify the custom format in RegisterProperty:

private static PropertyInfo<SmartDate> StartDateTimeProperty = 
RegisterProperty(c => c.StartDateTime, "Start Date & Time"
 SmartDate(DateTime.Now) {FormatString = "G"});

Troncho replied on Wednesday, June 10, 2015

Nice! I knew there had to be a better way Smile

Once again, thanks Jonny!

Copyright (c) Marimer LLC