Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the date format of a DateTimePicker in vb.net

How can I change the date format of a DateTimePicker in vb.net so that the date is shown in the format dd/mm/1990, without any time value? I have tried changing the format to "short", and while this provides the date formatting I require it does not remove the time.

like image 715
Failed_Noob Avatar asked Apr 26 '11 15:04

Failed_Noob


People also ask

How do you format a date?

Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.

What is date/time picker in Visual Basic?

Developing AutoCAD Plugins using VB.NET with Windows Forms The DateTimePicker control allows selecting a date and time by editing the displayed values in the control. If you click the arrow in the DateTimePicker control, it displays a month calendar, like a combo box control.

How do I change date picker format in Excel?

Display the current date and time in a date pickerClick the Data tab. In the Data type box, click Date and Time (dateTime). Click Format. In the Date and Time Format dialog box, in the Display the time like this list, click the option that you want, and then click OK.

What is a date time picker?

The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. The DateTimePicker control makes it easy to work with dates and times because it handles a lot of the data validation automatically.


2 Answers

You need to set the Format of the DateTimePicker to Custom and then assign the CustomFormat.

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    DateTimePicker1.Format = DateTimePickerFormat.Custom
    DateTimePicker1.CustomFormat = "dd/MM/yyyy"
End Sub
like image 102
David Hall Avatar answered Sep 28 '22 00:09

David Hall


Use:

dateTimePicker.Value.ToString("yyyy/MM/dd")

Refer to the following link:

http://www.vbdotnetforums.com/schedule-time/15001-datetimepicker-format.html

like image 36
Akram Shahda Avatar answered Sep 28 '22 00:09

Akram Shahda