-2
DateTime dt=new DateTime(05/06/2014) this is in dd/mm/yyyy)

dt.DayOfWeek raturns value based on mm/dd/yyyy format its taking 5 as month 6 as date. i want this has return a value based on dd/mm/yyyy format.

Please help me guys.

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
AnkiReddy L
  • 33
  • 1
  • 3

5 Answers5

1

Use this:

DateTime(Int32, Int32, Int32) Initializes a new instance of the DateTime structure to the specified year, month, and day.

DateTime dt = new DateTime(2014,6,5);

You can print the date in your specific format:

String.Format("{0:MM/dd/yyyy}", dt);          // "05/06/2014"
String.Format("{0:dd/MM/yyyy}", dt);          // "06/05/2014"

MSDN

Amir Popovich
  • 29,350
  • 9
  • 53
  • 99
1

try using this:

DateTime dt=new DateTime(05/06/2014)
String.Format("{0:dd/MM/yyyy}", dt); 

Correct overload for DateTime is

DateTime(int32 year, int32 month, int32 day)

DateTime

Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76
0

You are using wrong Contructor, you have to use this Contructor:

DateTime dt = new DateTime(int year, int month, int day);

DateTime(Int32, Int32, Int32) Initializes a new instance of the DateTime structure to the specified year, month, and day.

See its detail here

you can see here on MSDN the list of all Contructors avaiable of DateTime class.

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
0

Predefined datetime structure properties are working based on the Date and time format present in the Regional setting in your system. If you want to use a datetime for your application, you may refer this thread

Set Default DateTime Format c#

Community
  • 1
  • 1
Sathish
  • 29
  • 5
0

In datetime function , you also give string format as you required like

DateTime dt = DateTime.ParseExact(yourObject.ToString(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);

string s = dt.ToString("dd/M/yyyy");

or  

string s new datetime().ToString(give format here);

refer link convert datetime to date format dd/mm/yyyy

How to convert date format to DD-MM-YYYY in C#

Community
  • 1
  • 1
Ajay2707
  • 5,690
  • 6
  • 40
  • 58