Solved date format on vba (1 Viewer)

Akai90

Member
Local time
Today, 11:00
Joined
Feb 8, 2022
Messages
65
hai

i have this code..
trktmtsementara = DateAdd("M", tempohsementara, tarikhsementara)

how can i set the date format to dd mmmm yyyy
i try to set via property sheet but not working

my full code
Private Sub trktmtsementara_GotFocus()
If tempohsementara = "6" Then
trktmtsementara = DateAdd("M", tempohsementara, tarikhsementara)
Else
If tempohsementara = "1" Then
trktmtsementara = "31 Disember " & Year(tarikhsementara) + IIf(tempohsementara > 1, tempohsementara, IIf(Year(tarikhsementara) > 1, 0, 1))
End If
End If
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:00
Joined
Sep 21, 2011
Messages
14,287
Not sure why that would be?
1654162351264.png

1654162380096.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:00
Joined
May 7, 2009
Messages
19,238
on Design view of your Form, Click on tarikhsementara textbox.
on it's Property (Right Panel)->Format , put the format that you want (dd mmmm yyyy).
Code:
Private Sub trktmtsementara_GotFocus()
Dim n As Integer
n = Val(tempohsementara & "")
If tempohsementara = 6 Then
trktmtsementara = DateAdd("M", tempohsementara, tarikhsementara)
Else
If tempohsementara = 1 Then
trktmtsementara = DateSerial(Year(tarikhsementara) + IIf(tempohsementara > 1, tempohsementara, IIf(Year(tarikhsementara) > 1, 0, 1)), 12, 31)
End If
End If
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:00
Joined
Feb 19, 2002
Messages
43,266
I don't see how the question relates to the code. Granted, the language of the code is interfering with my understanding but you would never format a date to use it in a calculation. Date formats are for humans not for computers. Internally dates are stored as double precision numbers and they represent the number of days since Dec 30, 1899. A date prior to Dec 30, 1899 would be a negative number so, Dec 29, 1899 6PM would be -1.75 and Dec 28, 1899 at noon would be -2.5

print Now()
6/2/2022 6:44:28 PM

print cdbl(Now())
44714.7808217593

So there are 44,714 days since Dec 30, 1899 and it is approximately 3/4 of the way through the day. 6 PM would be .75 and 6:44:28 is .7808217593.

SQL Server and Excel use the same method except they use different origin dates. I think they both use Jan 1, 1900 as the origin date so the value they store would be 44712 for the date. The time value would be the same.

Access does the math using the numeric value and then converts the result to a string so that a human can understand it.
 

Users who are viewing this thread

Top Bottom