Failed_Noob
Failed_Noob

Reputation: 1357

Date and Time Format Problems in vb.net

I am trying to truncate the seconds part from the current Date

  Dim nowTime As DateTime = Now.ToShortTimeString

The above code shows time in the format

hh:mm:ss

I want it in the format

hh:mm


The Date Time Picker shows date like this

5/ 1/2011

(There is a space before 5 and before 1)

 Dim nowTime As DateTime = Now.ToShortTimeString

The above code shows Date like this

5/1/2011

(There is no space before 5 or 1)


I am trying to compare the current Date and time with the Date and Time in the database.

In the database I have saved the Date and Time as string.

Upvotes: 0

Views: 2142

Answers (3)

Vishwanath Dalvi
Vishwanath Dalvi

Reputation: 36601

String.Format("{0:HH:mm}", DateTime.Now)

Upvotes: 2

Caspar Kleijne
Caspar Kleijne

Reputation: 21864

you need to apply a correct FormatString with DateTime.ToString() like

dateValue.ToString("hh:mm")

and for the date:

Now.ToString("MM/dd/yyyy")

more here

Upvotes: 1

Akram Shahda
Akram Shahda

Reputation: 14781

Use the following:

String format = "What ever format you want"; // Examples: "hh:mm", "MM/dd/yyyy"

String value = youDateTimeObject.ToString(format);

Read more about it.

Upvotes: 1

Related Questions