Hi group, I’m sorting my table. With the amounts in Euro it works, and now I’m moving on to sorting the dates.
On the ListBox I see the dates in the format dd-mm-yyyy, and I would like to sort them using the RowComparision, so I acquire them with the following code, which however gives me an error, does it depend on the format?
Var n1 as datetime=datetime.FromString(Me.CellTextAt(row1,column))
Var n2 as datetime=datetime.FromString(Me.CellTextAt(row2,column))
The error is: Parse error: date needs to be in the format of YYYY-MM-DD HH:MM or YYYY-MM-DD
Can you go back a little and explain how are you adding the dates to the Listbox?
Are you pulling from a Database?
Are they stored on the database as dd-mm-yyyy, yyyy-mm-dd or other format (maybe seconds from 1970)?
if DatumGroesser(me.CellTextAt(row1,column),me.CellTextAt(row2,column)) then
result=1
else
result=-1
End if
return true
Dabei ist
Public Function DatumGroesser(pDatum1 as String, pDatum2 as String) As Boolean
var datum1, datum2 as double
var dasDatum as DateTime
dasDatum=ErzeugeDateTimeAusString(pDatum1)
if dasDatum<>nil then
datum1=dasDatum.SecondsFrom1970
else
datum1 =0
end if
dasDatum=ErzeugeDateTimeAusString(pDatum2)
if dasDatum<>nil then
datum2=dasDatum.SecondsFrom1970
else
datum2 =0
end if
return datum1> datum2
End Function
und letztlich
Public Function ErzeugeDateTimeAusString(pString as String) As DateTime
var tag, monat, jahr as integer
try
tag=pString.NthField(“-”, 1).val
monat=pString.NthField(“-”, 2).val
jahr=pString.NthField(“-”, 3).val
return New DateTime(jahr, monat, tag)
Catch err As InvalidArgumentException
return nil
End Try
End Function
Das kann man vielleicht noch optimieren, aber so geht es jedenfalls.
it is possible to store any object or value in the CellTag beside the visible Cell (which is only a string format).
a date from database should be possibly a datetime object.in xojo, you can store it in this celltag or as example the seconds since 1970, so you have a ready date object or a value to compare with < = >
I wanted to convert my date 02/12/2024 to 2024/12/02 … but it gives me an error. Can I convert the date from European format to American format, or do I have to convert to seconds?
Error is: “Date is not in an accepted format for parsing”
Var n1 As DateTime
Var n2 As DateTime
Var tz As new TimeZone(“America/New_York”)
Var lc As new Locale(“en-US”)