Converting date format in VBA

mcdhappy80

Registered User.
Local time
Today, 05:25
Joined
Jun 22, 2009
Messages
347
I noticed that date imported to VBA depends on Standards and Format, in Control Panels, Regional and Language Options settings.
For example in one regional settings the date is displayed in format 01. September. 2009 while in other regional settings the date is stored like September, 1st 2009, for example.
I was wondering, is there a way, that no matter what regional settings are, date imported in VBA can be converted to desired date format?
Is there a function in VBA that can do this?
If not, lets build one, and what strategies would You recommend in doing so?
Thank You.
 
dates are stored as numbers. to work with dates in code you must use the m/d/y approach, presumably because Access is made in the states. you can display dates however you like by formatting.
 
I tried this code:
Code:
Private Sub btnFormat_Click()

Dim dteSistemskiDatum As Date
Dim dteFormatiranDatum As Date

dteSistemskiDatum = Date
dteFormatiranDatum = Format(dteSistemskiDatum, "dd")

MsgBox "Sistemski Datum = " & dteSistemskiDatum
MsgBox "Formatiran datum " & dteFormatiranDatum

Me.txtSisDatum = dteSistemskiDatum
Me.txtFormDatum = dteFormatiranDatum

End Sub
What I don't understand here is that dteFormatiranDatum has the value 1/18/1900.
Can someone explain how do I use Format() function with dates?
Can i display the date in the format dd. mmmm. yyyy? I tried typing:
dteFormatiranDatum = Format(dteSistemskiDatum, "dd. mmmm. yyyy")
but I'm getting datatype mismatch error, why?

Thank You
 

Users who are viewing this thread

Back
Top Bottom