I need to print the date in the format of mm/dd/yyyy. if the date is 4/24/2009 it should print the date as 04/24/2009. that is zero padding is also needed.. I used date function to get the current date...but the date is getting in the format of m/dd/yyyy...
Tested in the immediate window and is working for me (output as a comment)
Format(Now, "MM/dd/yyyy") '04/29/2009
Format(Date, "MM/dd/yyyy") '04/29/2009
Format(CStr(Now), "MM/dd/yyyy") '04/29/2009
Format(Date$, "MM/dd/yyyy") '04/29/2009
Format(CDate(Date), "MM/dd/yyyy")'04/29/2009
So whether it is string or datetime should not matter.
Edit: Saw your comment to Fredrik. It doesn't matter how it looks like when you save it to the db table (column date format would be a property of the db and not your program's (or vb's) responsibility). Just format the value as and when you retrieve it from the db.
Note that the "/" character in date formatting functions has a special meaning, as "date separator". This means that i may be replaced with the date separator for the current locale that the program is executed in (here in Sweden it would be replaced with "-" for instance). In order to ensure that you do indeed get the "/" character in the output, I think this would work (I don't have a VB installation to verify with):
Format(date, "MM'/'dd'/'yyyy")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With