B4J Question [SOLVED][JStringFunctions] .DayOfMonth(), Fails in B4J?

Dadaista

Active Member
Licensed User
Longtime User
Hi

Today is november 28
B4X:
sAux2 = sf.DayOfMonth (sf.Today())
Above line returns 11.. it seems return month?

This is the sub:
B4X:
Sub sNombreFichero As String
    Dim sAux As String
    Dim sAux2 As String
    sAux = sf.Year (sf.today())
    sAux2 = sf.Month (sf.Today())
    If sAux2.Length = 1 Then sAux2 = "0" & sAux2
    sAux = sAux & sAux2
    sAux2 = sf.DayOfMonth (sf.Today())
    If sAux2.Length = 1 Then sAux2 = "0" & sAux2
    sAux = sAux & sAux2
    Return sAux
End Sub

It returns "20171111"

The same sub works In B4A o_O:eek:o_O:eek:
 

Daestrum

Expert
Licensed User
Longtime User
Could you not use DateTime for the functions?
ie,
B4X:
...
    Dim now As Long = DateTime.Now
    Log(DateTime.GetDayOfMonth(now))
    Log(DateTime.GetMonth(now))
    Log(DateTime.GetYear(now))
..
if you wanted yyyyMMdd then you can use
B4X:
DateTime.DateFormat = "yyyyMMdd"
Log(DateTime.Date(DateTime.Now))

Don't forget to save the original DateFormat in a String , so you can set it back to default.
B4X:
Dim oldFormat as String = DateTime.DateFormat
' do your work here
DateTime.DateFormat = oldFormat
...
 
Last edited:
Upvote 0

Dadaista

Active Member
Licensed User
Longtime User
Hi

Thx for your replies Daestrum and Erel!!

Yes, I have changed the sub in B4j and B4A too :)

Regards!!
 
Upvote 0
Top