Search code examples
c#xamldatepickerwindows-store-appswindows-8.1

Get date from DatePicker using c# in windows store app


I want to insert date value in my database I have a class which have a date time attribute like this

public DateTime BookingDate { get; set; }

I have a date picker in my xaml page named datepicker . I want to insert only date value , How to get date using c#??


Solution

  • You can use the Date Property , follow the documentation

      DateTimeOffset sourceTime = YourDatePicker.Date;
      BookingDate = sourceTime.DateTime;
    

    To convert back to offset and bind to datetimepicker

       DateTime newBookingDate;
       newBookingDate = DateTime.SpecifyKind(BookingDate, DateTimeKind.Utc);
       DateTimeOffset bindTime = newBookingDate;
       YourDatePicker.Date = bindTime;
    

    Adding a DatePicker (XAML)