Dani Danish
Dani Danish

Reputation: 23

How to get Date from DateTimePicker.CustomFormat

How i can get only Date with datetime datatype from DateTimePicker.CustomFormat("dd");

datetimepicker1.CustomFormat = "dd";

it gives me full date but i need onlye Day on month like 05 I am also Storing the datetimepicker value in the database and the database column have datetime datatype

Upvotes: 0

Views: 165

Answers (3)

Sathish
Sathish

Reputation: 309

Use Following Code,

datetimepicker1.SelectedDate.Day();

Upvotes: 0

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

Problem : you have set only the CustomFormat Property of the DateTimePicker control without Changing the Format of the DateTimePicker control to Custom.

Solution : You need to set Format of the DateTimePicker control to Custom

Try This:

datetimepicker1.Format = DateTimePickerFormat.Custom;
datetimepicker1.CustomFormat = "dd";

Solution 2: if you want to get only Date part from the Selected Date value you can use Day property of DateTimePicker.

Try This:

int day=dateTimePicker1.Value.Day;

Upvotes: 1

Pradip
Pradip

Reputation: 1537

You can use this :

dateTimePicker1.Value.ToString("dd");

Check here for more formatting options.

Upvotes: 0

Related Questions