hb_DateTime to String

166 views
Skip to first unread message

Luigi Ferraris

unread,
Oct 22, 2025, 11:29:16 AM (8 days ago) Oct 22
to Harbour Users
Hi friends
I need to convert a hb_DateTime value to string in this way:

dateTime := hb_DateTime( 2025, 7, 31, 11, 35, 45, 759 )
or
dateTime := hb_DateTime( 2025, 7, 31 )
or
dateTime := hb_DateTime( 0, 0, 0, 11, 35, 45, 759 )

to 

format := "DD/MM/YYYY"
string := functionName( dateTime, format )
or
format := "HH:MM"
string := functionName( dateTime, format ) 
or
format := "YYYY/MM/DD HH:MM"
string := functionName( dateTime, format ) 

Is there a Harbour function or I must create a function?
I know hb_TtoC, but need two separated formats: datePart and timePart.

Many thanks in advance for any info.
Regards, Luigi

Hurricane

unread,
Oct 22, 2025, 12:40:00 PM (8 days ago) Oct 22
to harbou...@googlegroups.com
Hi,
see here (small index by subject, multiple pages)

Regards,
Hurricane


Maurizio la Cecilia

unread,
Oct 22, 2025, 12:48:05 PM (8 days ago) Oct 22
to harbou...@googlegroups.com
Hi Luigi,
please try this:
  • hb_TtoC( <dDate>|<tTimeStamp> [, <cDateFormat>, <cTimeFormat>] )  cTimeStamp
    converts date or timestamp values to timestamp formatted strings.

Best regards.
--
Maurizio
--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/ebae050c-489a-4601-8226-95a3bda04b41n%40googlegroups.com.


Luigi Ferraris

unread,
Oct 23, 2025, 6:04:56 AM (8 days ago) Oct 23
to Harbour Users
Hi friends,
many thanks for your answers, but as I wrote I know hb_TtoC etc. functions.

My problem was to use only one string format to convert ANY datetime value
without know if datetime is: timeStamp, date or time and discarding unset part.
It's a long story, I don't want boring anyone.
Probably, I need to rethink about usage of hb_DateTime as fundamental data type,
but declaring if it's a: Date, Time or TimeStamp.

Regards, Luigi

Hurricane

unread,
Oct 23, 2025, 8:37:11 AM (7 days ago) Oct 23
to harbou...@googlegroups.com
It seems like you didn't see what I told you, it has what you need.


Aleksander Czajczyński

unread,
Oct 23, 2025, 12:34:12 PM (7 days ago) Oct 23
to Harbour Users
Hello Luigi!

Now it's a bit hard to understand what you ask for.

LOCAL dateTime := hb_DateTime( 2025, 7, 31, 11, 35, 45, 759 )

? hb_TToC( dateTime, "DD/MM/YYYY", "" ) // - >   31/07/2025
? hb_TToC( dateTime, "", "HH:MM" ) // ->  11:35

IMHO, this function does what you describe.

Best regards, Aleksander

Aleksander Czajczyński

unread,
Oct 23, 2025, 12:48:32 PM (7 days ago) Oct 23
to Harbour Users
A further play with some checks:
https://os.allcom.pl/hb/#!eJyNjzsPgjAUhXd-xbETJBiKjxgdNEohdCgSqIMTwWgig48YFv-9LRKBRIl9JL293zmnDXaRJ_k2gsiLq2kZBoD4UVxLJk2cDxnLy5MsLicTIzqa2pjZGLs2XLXHqpzoq-kcFqw_lfSz-kUfrh31U9MJqSBNJb7cJRGoYcTJ1mtExzqlxlYgwyHRJx5gAP9yL5-Vs5Q31qbVdBwNfestQY8U2qWyfCNeg9ggjDlCOHs1iKrI-yt-xHhQh4ebjKeSCz-VaxF3Htrnq93CcCFE2_IF-9d0NA

FUNCTION Main()

   PrintDT( hb_DateTime( 2025, 7, 31, 11, 35, 45, 759 ) )
   PrintDT( hb_DateTime( 2025, 7, 31, 0, 0, 0, 0 ) )
   PrintDT( hb_DateTime( 0, 0, 0, 11, 35, 45, 0 ) )
   PrintDT( hb_Date( 2025, 7, 31 ) )

   RETURN 0

PROC PrintDT( dateTime )

   ? "--"
   IF ! Empty( hb_TToD( dateTime ) ) // IF hb_TToD( dateTime ) > 0d0
      ? hb_TToC( dateTime, "DD/MM/YYYY", "" )
   ENDIF
   IF HB_ISTIMESTAMP( dateTime )

      ? hb_TToC( dateTime, "", "HH:MM" )
   ENDIF

Reply all
Reply to author
Forward
0 new messages