Name of backup file (1 Viewer)

hfsitumo2001

Member
Local time
Today, 07:42
Joined
Jan 17, 2021
Messages
365
I want to include the hours and minute and second of the day we backup in the file name. I tried to put like this but syntax error can anyone help me what is the good format?

Target = Path & "\EVSbkupDB_" & Format(Now(), "mm-dd-yyyy-hh-nn-ss") & ".accdb"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:42
Joined
May 7, 2009
Messages
19,233
describe the "Path".
 

Isaac

Lifelong Learner
Local time
Today, 07:42
Joined
Mar 14, 2017
Messages
8,774
Format(now, "mm-dd-yy-hh-mm-ss")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:42
Joined
May 7, 2009
Messages
19,233
Format(now, "mm-dd-yy-hh-mm-ss")
i don't see any difference?

tested this part:

Format(Now(), "mm-dd-yyyy-hh-nn-ss") & ".accdb"

and is Valid.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:42
Joined
Oct 29, 2018
Messages
21,456
In Format(), "m" = month and "n" = minutes.
 

Isaac

Lifelong Learner
Local time
Today, 07:42
Joined
Mar 14, 2017
Messages
8,774
i don't see any difference?

tested this part:

Format(Now(), "mm-dd-yyyy-hh-nn-ss") & ".accdb"

and is Valid.
the difference is he had "nn", the correct is "mm"
 

Isaac

Lifelong Learner
Local time
Today, 07:42
Joined
Mar 14, 2017
Messages
8,774
In Format(), "m" = month and "n" = minutes.
I use it the way I did it all the time - literally every day. It works fine. It's "n" in some context, but not all. In fact I've discovered that most of the Special Formats in Excel actually can be used in the vba Format() function!

Try this - you'll see it correctly differentiates "mm" for month as well as "mm" for minutes:

1612970073451.png


Thank you Isaac. God bless you
Glad it helped! Good luck with your project
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:42
Joined
Oct 29, 2018
Messages
21,456
I use it the way I did it all the time - literally every day. It works fine. It's "n" in some context, but not all. In fact I've discovered that most of the Special Formats in Excel actually can be used in the vba Format() function!

Try this - you'll see it correctly differentiates "mm" for month as well as "mm" for minutes:

View attachment 89086


Glad it helped! Good luck with your project
Hi. I would rather be safe than get caught by surprise. Try these:
Code:
?Format(Now(), "nn")

?Format(Now(), "mm")
Surprise!!!
 
Last edited:

Minty

AWF VIP
Local time
Today, 15:42
Joined
Jul 26, 2013
Messages
10,368
Actually, I'm with @theDBguy on this one - mm for minutes (although it works sometine) is dodgy and I'm surprised.

I've always used "nn" for the minutes in Access.
EDIT: And I don't think "mm" will every give you the minutes in a Datepart() expression?
 

Isaac

Lifelong Learner
Local time
Today, 07:42
Joined
Mar 14, 2017
Messages
8,774
Hi. I would rather be safe than get caught by surprise. Try this:
Code:
?Format(Now(), "nn")

?Format(Now(), "mm")
Surprise!!!
Right - it's only when you bundle them together in my magic sequence that it works ;)

I hear what you're saying - But - it's not really dodgy, nor a surprise nor unsafe. From Format function (Visual Basic for Applications) | Microsoft Docs:

1612972426409.png


..."m" is just as much for minutes as "n" is, as long as sequence is taken into account.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:42
Joined
May 7, 2009
Messages
19,233
the difference is he had "nn", the correct is "mm"
there is no Difference.
you can test it yourself.

?Format$(Now, "hh-mm")
?Format$(Now, "hh-nn")

no difference, right?
and here is the original post (post#1):

Target = Path & "\EVSbkupDB_" & Format(Now(), "mm-dd-yyyy-hh-nn-ss") & ".accdb"
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 07:42
Joined
Oct 29, 2018
Messages
21,456
..."m" is just as much for minutes as "n" is, [BUT] as long as sequence is taken into account.
I see a "but" in there... :)

Like I said though, it's certainly an option, but why not just use what was purposely created for it? What if "someday" MS decides to take the option away? I know it's a big "IF," but I'm just playing it safe. However, I can't tell you how to gamble with your money. ;)
 

Isaac

Lifelong Learner
Local time
Today, 07:42
Joined
Mar 14, 2017
Messages
8,774
I see a "but" in there... :)

Like I said though, it's certainly an option, but why not just use what was purposely created for it? What if "someday" MS decides to take the option away? I know it's a big "IF," but I'm just playing it safe. However, I can't tell you how to gamble with your money. ;)
Play by the rules and you'll be fine either way.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:42
Joined
Feb 19, 2002
Messages
43,224
I'm not sure when that rule was added but in the past, you always had to use nn for hours regardless of context. "nn" is unambiguous so I probably won't change my coding style.

VBA is actually a terrible language. It is way too flexible and there are too many ways to do certain things. And over time, MS has made it even more forgiving for non-programmers allowing them to be sloppy and still survive.
 

isladogs

MVP / VIP
Local time
Today, 15:42
Joined
Jan 14, 2017
Messages
18,209
I'm not sure when that rule was added but in the past, you always had to use nn for hours regardless of context. "nn" is unambiguous so I probably won't change my coding style.

VBA is actually a terrible language. It is way too flexible and there are too many ways to do certain things. And over time, MS has made it even more forgiving for non-programmers allowing them to be sloppy and still survive.
I think you meant use nn for minutes!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:42
Joined
Feb 19, 2002
Messages
43,224
Thanks for the correction:) I just washed my hands and can't do a thing with them.
 

Users who are viewing this thread

Top Bottom