ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time formatting (https://www.excelbanter.com/excel-programming/302848-re-time-formatting.html)

JE McGimpsey

Time formatting
 
First, 1805 is 6:05 PM, not 8:05 PM.

Try:

fName = Format(Date,"mmddyyyy")
tName = Format(Time,"hhmm")

However, for sorting files, I'd recommend you use yyyymmdd instead:

20040604



In article ,
"jeffP" wrote:

I'm trying to get this to show leading zeros but I'm stuck. I'm using it to
SaveAs a filename so it must be text without special characters, etc.
It works fine except single days (1-9)would show poorly 642004 (June 4th)
is hard to read and minutes are worse. Zero to 9 shows no leading 0 thus
8:05 PM would be 185 instead of military 1805.
Any help would be appreciated.
Dim fname As String
Dim tname As String

fname = Format$(month(Now()) & Day(Now()) & Year(Now()),
"@@@@@@@@_")
tname = Format$(Hour(Now()) & Minute(Now()), "@@@@_")



All times are GMT +1. The time now is 08:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com