xHarbour Reference Documentation > Function Reference |
Converts a Date value to a character string in YYYYMMDD format.
DtoS( <dDate>) --> cYYYYMMDD
The return value is a character string in YYYYMMDD format. DtoS() returns Space(8) for an empty date.
This function converts a Date value to a character string that is independent from the settings SET CENTURY, SET DATE and SET EPOCH. Therefore, DtoS() and its counterpart StoD() are the recommended Date to Character string conversion functions, unless a Date value must be output in a country specific format.
When Date fields are combined with Character fields in an index expression, use DtoS() to concatenate the Date field with the Character field. This ensures that the Date field is sorted in chronological order.
See also: | CtoD(), Date(), DtoC(), INDEX, StoD(), TtoS() |
Category: | Conversion functions , Date and time |
Source: | rtl\dateshb.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example illustrates sorting of date formatted character strings // and how it is influenced by the date format. PROCEDURE Main LOCAL aDate := { StoD( "20060209" ), ; StoD( "20060303" ), ; StoD( "20060106" ) } SET DATE TO ITALIAN // dd-mm-yyyy // using DtoC() ASort( aDate,,, {|d1,d2| DtoC( d1 ) < DtoC( d2 ) } ) AEval( aDate, {|d| QOut(Day(d), CMonth(d) ) } ) /* result: 3 March 6 January 9 February */ // using DtoS() ASort( aDate,,, {|d1,d2| DtoS( d1 ) < DtoS( d2 ) } ) AEval( aDate, {|d| QOut(Day(d), CMonth(d) ) } ) /* result: 6 January 9 February 3 March */ RETURN
http://www.xHarbour.com