-1

I am trying to convert a date from 19/10/2012 00:00:00 to 19/10/2012. I can't state the date type in the viewmodel like here as code is as below:

Viewmodel:

public Appointment Appointment {get; set;}

I am aware that mapping is an option but would like to see if an alternate option is available as this will make reusing the code easier and if the service changes at all then mapping will complicate things.

Mock service example:

public class Appointment
    {
        [DataMember]
        public DateTime AppointmentDate { get; set; }  
        [DataMember]
        public Identifier AppointmentIdentifier { get; set; }
        [DataMember]
        public string Location { get; set; }
        [DataMember]

    ...etc
Community
  • 1
  • 1
ShufflerShark
  • 377
  • 1
  • 4
  • 20
  • This wouldn't happen to be your question here? Seems somewhat similar. I'm calling a dupe. http://stackoverflow.com/questions/12975381/get-date-from-datetime-without-toshortdatestring – spender Oct 19 '12 at 14:45
  • 2
    I have to ask why are you not just assigning it to the DateTime as is? – ChrisBint Oct 19 '12 at 14:45
  • 1
    A datetime **isn't** a string like "19/10/2012 00:00:00" or "19/10/2012". These are string representations (or serializations) of a datetime. You can't have half an object. DateTime. Date. Time. Perhaps you want to affect the serialization process somehow. Perhaps you should deal with this the other end, but you can't lop fields/properties off a type from the BCL. – spender Oct 19 '12 at 14:48

2 Answers2

0

my solution is that you define a field like _AppointmentDate and then, in its property return whatever date format you want

Babak Fakhriloo
  • 2,076
  • 4
  • 44
  • 80
0

Have you tried returning the AppointmentDate as a string and then casting it back to DateTime?

Razvan Trifan
  • 534
  • 2
  • 6