in my wpf app, i am using datepicker control to select dates which is shown below:
<DatePicker Name="dtpSales" Grid.Row="3" SelectedDate="{Binding SalesDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, TargetNullValue ={x:Static System:DateTime.Now}}" Width="200" Height="24" HorizontalAlignment="Left" Margin="147,7,0,5" BorderBrush="Black" Grid.ColumnSpan="2" />
And I am able to save the date in mm-dd-yyyy format. How do i save it in 25-05-2019 format ??? The binded SalesDate is a DateTime datatype.
EDITED : I have a date object with value 12-02-2019 (dd-MM-yyyy) and it is saved to sql server table as 2019-12-02 (yyyy-dd-MM). When i retrieve the date from the database, the value of the date will be 02-12-2019 (MM-dd-yyyy). And Now I want to add 4 months to that date.
int salesid = (int)dr["SalesID"]; // dr is the datarow
DateTime salesdate = (DateTime)dr["SalesDate"];
string sdate = salesdate.AddMonths(4).ToString("dd-MM-yyyy");
DateTime servicedate = Convert.ToDateTime(sdate); // 2020-12-02
When I am adding 4 months to 02-12-2019, it will become 2020-12-02 ??? I am not able to get the correct date when i am adding just 4 months to 02-12-2019.