xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

DtoS()

Converts a Date value to a character string in YYYYMMDD format.

Syntax

DtoS( <dDate>)  --> cYYYYMMDD

Arguments

<dDate>
The parameter must be a value of data type Date.

Return

The return value is a character string in YYYYMMDD format. DtoS() returns Space(8) for an empty date.

Description

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.

Info

See also:CtoD(), Date(), DtoC(), INDEX, StoD(), TtoS()
Category: Conversion functions , Date and time
Source:rtl\dateshb.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe