-1

Whenever i choose the date from datepicker the date will flip with month position.

i tried to convert the date format from dd/MM/yyyy to MM/dd/yyyy and reverse also but the selected date is flipping the date to month.

$(function () {

    $("#<%= txtDatePicker.ClientID %>").datepicker({
        autoclose: true,
        dateFormat: "dd/MM/yyyy"
    });

    $("#<%= txtDatePicker1.ClientID %>").datepicker({
        autoclose: true,
        dateFormat: "dd/MM/yyyy"
    });
});

C# code is

  var dateAndTime = Convert.ToDateTime(txtDatePicker.Text);
            var date = dateAndTime.Date;

Or try to converted to string and change the format

string d1 =txtDatePicker.Text;
d1.ToString("dd/MM/yyyyy")

nothing helps.

if i want to choose the date between 01-Aug-2019 and second date 29-Sep-2019.

haldo
  • 14,512
  • 5
  • 46
  • 52
NAJEEB
  • 251
  • 2
  • 13

1 Answers1

0

You can use ParseExact to convert date from specific format. Suppose you are getting date as dd/MM/yyyy then

DateTime date = DateTime.ParseExact(txtDatePicker.Text, "dd/MM/yyyy", null)

For more info Converting dd/mm/yyyy formatted string to Datetime

Karan
  • 12,059
  • 3
  • 24
  • 40