We help IT Professionals succeed at work.

System.DateTime.Now.Day.ToString("DD")

dba123
dba123 asked
on
Medium Priority
4,773 Views
Last Modified: 2008-01-09
System.DateTime.Now.Day.ToString("DD") is not working.  I want to return 03, no 3 for day 3
Comment
Watch Question

Try

MessageBox.Show(Format(Now.Day, "00"))

HTH :)
CERTIFIED EXPERT

Commented:
try lower case "dd"
CERTIFIED EXPERT

Commented:

Author

Commented:
for some reason, it's putting dd in the string such as 04dd for this:

System.DateTime.Now.ToString("MM") & System.DateTime.Now.Day.ToString("dd")

why is the month working but not the day in this case?
CERTIFIED EXPERT

Commented:
Dim MyDate As New DateTime(now)
Dim MyString As String = MyDate.ToString("dd")

Author

Commented:
why can't I do it as I did the month?

Author

Commented:
System.DateTime.Now.ToString("MM") works

Author

Commented:
Dim MyDate As New DateTime(now)

Error: Value of type 'Date' cannot be converted to 'Long'.

I'd still prefer to do it this way, just like I did for month: System.DateTime.Now.Day.ToString("dd")
Commented:
System.DateTime.Now.Day.ToString("dd")

should be:

System.DateTime.Now.ToString("dd")

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT

Commented:
Dim fun As Date
      fun = Now
      MsgBox(Format(fun, "dd"))
What AlexFM says works for me
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.