Date Formatting problem

K

Kerri

Hi,

I have an ASPX page with a textbox where the user enters a
date.

I have a variable of tyope date that I populate from teh
form
d

dtMyDate = Request.Form("txMyDate")

I then call a function that formats my date.

Public Function FormatDate(ByVal dtMyDate as date) as Date

FormatDate = Format(dtMyDate, "mm/dd/yyyy")
End Function


If I pass in the date 01/01/2003, it formats it as
00/01/2003.

Any ideas why this is.

Thanks,
Kerri.
 
S

Steven Campbell

Kerri said:
Public Function FormatDate(ByVal dtMyDate as date) as Date

FormatDate = Format(dtMyDate, "mm/dd/yyyy")
End Function


If I pass in the date 01/01/2003, it formats it as
00/01/2003.

Any ideas why this is.

Your function does not really do any formatting, since it returns a
"Date" datatype, which is not formatted. If it returned a string, then
it should work.

I also thought the correct syntax was:
return Format(dtMyDate, "mm/dd/yyyy")

If it compiles, I guess its fine, but I like the "return" syntax better
than the old VB6 syntax that you are using, mainly because it is easier
to read, and makes renaming the function much simpler.
 
Y

yop

Hello

I saw this and found it works perfect.

Dim rightNow As DateTime = DateTime.Now
Dim sDateTime As String

sDateTime = rightNow.ToString("MM/dd/yyyy")
 
J

Jerry III

"mm" in date format string means minute, not month. Month is what yop used,
MM.

Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top