Reputation: 3718
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#??
Upvotes: 0
Views: 3166
Reputation: 4161
Using an MVVM Pattern:
View (XAML):
<DatePicker Date="{Binding DateOffset, Mode=TwoWay}" />
ViewModel (C#):
private DateTime Date { get; set; }
public DateTimeOffset DateOffset
{
get { return DateTime.SpecifyKind(Date, DateTimeKind.Utc); }
set { Date = value.DateTime; }
}
Upvotes: 0
Reputation: 222712
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;
Upvotes: 2