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

System.DateTime.Now.Day.ToString("DD") is not working.  I want to return 03, no 3 for day 3
LVL 1
dba123Asked:
Who is Participating?
 
AlexFMCommented:
System.DateTime.Now.Day.ToString("dd")

should be:

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

0
 
cubixSoftwareCommented:
Try

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

HTH :)
0
 
Mikal613Commented:
try lower case "dd"
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
dba123Author 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?
0
 
Mikal613Commented:
Dim MyDate As New DateTime(now)
Dim MyString As String = MyDate.ToString("dd")
0
 
dba123Author Commented:
why can't I do it as I did the month?
0
 
dba123Author Commented:
System.DateTime.Now.ToString("MM") works
0
 
dba123Author 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")
0
 
Mikal613Commented:
Dim fun As Date
      fun = Now
      MsgBox(Format(fun, "dd"))
0
 
cubixSoftwareCommented:
What AlexFM says works for me
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.