Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a date in a certain format 1

Status
Not open for further replies.

paulcy82

Programmer
Jan 25, 2005
28
0
0
US
I need a variable that stores just a date and not the time. I also need the date to be stored in a certain format, YYYY-MM-DD, 2005-01-10. I have looked at the following:

Dim d As Date
Debug.Write(d.Today)
Debug.Write(d.Now)
Debug.Write(d.Date)
 
format([date variable], "MM/dd/yyyy")

look up the format command, there is tons of custom formating control on dates.

Also, the date is going to be stored in some arbitratry format (number of seconds since some date in the 1960s? what ever that deal is), so all you need to do is format the date when you need to interact with it (IE: Displaying it and saving it to a database)

-Rick

----------------------
 
You can also supply a format as a parameter to the ToString() method.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
I prefer the "Framework" way that ChipH mentioned. Make sure to use "MM" for month and "mm" for minute.

sDate = Date.Now.ToString("yyyy/MM/dd HH:mm")

See
"Custom DateTime Format Strings"

Compare Code
 
thank you for the help, I have an add on question to this now. I want to display yesterdays date. I have the following code that diplays todays date in the format that I need. How can I alter this to display yesterdays date in the same format.

Date.Now.ToString("yyyy-MM-dd")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top