I thought by setting up the custom format of date time picker to |MM/dd/yy hh:mm tt" would work, but the selection doesn't change from date picker only! I need an object that I can be able to choose both date and time.

Dani AI

Generated

A quick recap: the built-in picker returns a DateTime but its calendar drop-down is date-focused, so getting both a date and an explicit time usually means combining controls or using a control that exposes a time editor. attempted a custom format, and and highlighted reading the control value and switching to a time-only mode respectively. Below are practical options and a small pattern that works reliably.

Common approaches

  • Use two inputs: one for the date, one for the time, then build a single DateTime from their parts. This keeps UI simple and avoids fighting the built-in calendar UI.
  • Use a third-party datetime picker or build a small custom drop-down that contains a calendar plus hour/minute editors if you need a single compact control.
  • If you accept a spinner-style editor instead of a calendar drop-down, that’s a valid UX choice for time entry.

Combining date and time (example)

DateTime combined = new DateTime(
    datePicker.Value.Year,
    datePicker.Value.Month,
    datePicker.Value.Day,
    timePicker.Value.Hour,
    timePicker.Value.Minute,
    timePicker.Value.Second);

Storage and validation tips

  • Store timestamps as UTC or use DateTimeOffset to preserve absolute moments across time zones.
  • Persist in ISO 8601 (round-trip) format for safety when serializing.
  • Validate ranges (min/max), and choose sensible minute-step increments (5 / 15 minutes) to reduce input error.
  • Test AM/PM vs 24-hour cultures and keyboard-only workflows.

If the spinner solution you found works for your users, confirm it behaves correctly with different regional settings and that you combine and persist the resulting DateTime consistently.

Recommended Answers

All 3 Replies

..., but the selection doesn't change from date picker only! I need an object that I can be able to choose both date and time.

Can you please elaborate this issue a bit precisly?

and this works:

DateTime date = dateTimePicker1.Value;
string strDate = String.Format("{0:MM/dd/yy hh:mm tt}", date);

thx,
Mitja

You can use this, but then you can only select time
timePicker.Format = DateTimePickerFormat.Time;

I think I've done it. I set showupanddown to true and I can set now the time and date using an up and down scroll.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.