How to format a date in Harbour?

Asked

Viewed 42 times

2

I’m learning the language Harbour. I’m seeing how this language works with dates.

PROCEDURE MAIN()

    LOCAL date := Date()

    ? date

    RETURN

This is returning me:

02/10/21

How could I do to format this date to DD/MM/YYYYY, for example?

1 answer

3


To change the default presentation used in ?, SAY, GET etc.:

SET DATE german                      // Formatos pré definidos, legado
SET DATE FORMAT TO dd/mm/yyyy        // Formato customizável (pré processador)
Set( _SET_DATEFORMAT, 'dd/mm/yyyy' ) // Formato customizável (nativo)

Handbook: https://harbour.github.io/doc/harbour.html#set-date-cmd

To generate a formatted string:

hb_DToC( dData, cFormato )

Example:

? hb_DToC( 0d20210531, 'DD~MM~YYYY' )

Exit:

31~05~2021

If you want the same for a timestamp:

hb_TToC( tTimestamp, cFormatoData, cFormatoTempo )


For lack of detailed documentation, follow the official implementation:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.