Format() with Date.Now issue? (1 Viewer)

Access_guy49

Registered User.
Local time
Today, 01:27
Joined
Sep 7, 2007
Messages
462
Hey Everyone,
I was wondering if anyone has come accross an issue with the Format Function in which if you use the Date.now as the date, it messes up the date.
Example.
If date.now provides the system date as 20/6/2011
Using the Format( Date.now, "mm/dd/yyyy")
Gets you a random date such as
46/20/2011
I know it's not totally random, the problem is the single digit for the month. It seems to be using a random number to make it a double digit month, but i don't recall this ever happening in VBA in Access..
Any thoughts?
 

boblarson

Smeghead
Local time
Yesterday, 22:27
Joined
Jan 12, 2001
Messages
32,059
In VB.NET, you don't use Format for the date. In VB.NET you would use something like this:
Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Label1.Text = FormatDateTime(Now(), [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]DateFormat[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].ShortDate)
[/SIZE][/FONT][/SIZE][/FONT]
 

dan-cat

Registered User.
Local time
Today, 06:27
Joined
Jun 2, 2002
Messages
3,433
"mm" denotes minutes in VB.net, for month use "MM"

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

Just use the .ToString() extension method for the date type with the appropriate format, that way you can apply any format you want.
 

Users who are viewing this thread

Top Bottom