Page 1 of 1
"Text" Date/Time to "Number" ?
Posted: Sun Aug 14, 2022 8:30 am
by Jimmy
hi,
have write my own "phpBB Froum Grabber" but i have use HMG Syntax.
it work well with HMG and Xbase++ phpBB Forum but with FiveWin Forum i have Problem with Date/Time Format
» Thu Oct 06, 2005 6:24 pm </p>
» Thu Oct 06, 2005 8:28 pm </p>
» Fri Oct 07, 2005 7:11 pm </p>
» Sun Feb 26, 2006 9:17 am </p>
how can i convert those Date/Time String into his Format

Re: "Text" Date/Time to "Number" ?
Posted: Sun Aug 14, 2022 9:59 am
by cnavarro
Re: "Text" Date/Time to "Number" ?
Posted: Sun Aug 14, 2022 5:20 pm
by Jimmy
hi,
cnavarro wrote:https://github.com/Petewg/harbour-core/wiki/Date-Time
thx for Answer.
which hb_* Function is to use to convert "Oct 06, 2005" into Type "D"
which DATE Format is need
i do have
Re: "Text" Date/Time to "Number" ?
Posted: Mon Aug 15, 2022 9:00 am
by nageswaragunupudi
Do you wan to convert the string "» Thu Oct 06, 2005 6:24 pm </p>" into string "2005-10-06 18:24:00" ?
You said you could do it with Xbase++.
Can you please share your XBase++ code that does this conversion?
Re: "Text" Date/Time to "Number" ?
Posted: Mon Aug 15, 2022 7:36 pm
by Jimmy
hi,
nageswaragunupudi wrote:Do you wan to convert the string "» Thu Oct 06, 2005 6:24 pm </p>" into string "2005-10-06 18:24:00" ?
Yes
nageswaragunupudi wrote:You said you could do it with Xbase++.
Can you please share your XBase++ code that does this conversion?
there is not special Xbase++ Function to convert that String into Date/Time Format
i have made a ""Quick & Dirty" Function to convert
Code: Select all | Expand
FUNCTION StringDate( cLine, cTime )
LOCAL ii, nPosi, cMonth, cNext, cYear, nSec, cMore
LOCAL cYYYY, cMM, cDD, cHHMMSS
LOCAL aMonth := { "Jan", ;
"Feb", ;
"Mar", ;
"Apr", ;
"May", ;
"Jun", ;
"Jul", ;
"Aug", ;
"Sep", ;
"Oct", ;
"Nov", ;
"Dec" }
cTime := "00:00:00"
FOR ii := 1 TO LEN( aMonth )
IF aMonth[ ii ] $ cLine
cMM := STRZERO( ii, 2 )
cMonth := aMonth[ ii ]
EXIT
ENDIF
NEXT
IF EMPTY( cMM )
RETURN CTOD( " . . " )
ENDIF
nPosi := AT( "»", cLine )
IF nPosi > 0
cLine := SUBSTR( cLine, nPosi + 7 )
ELSE
RETURN CTOD( " . . " )
ENDIF
// » Thu Oct 06, 2005 6:24 pm </p>
nPosi := AT( cMonth, cLine )
IF nPosi > 0
cNext := SUBSTR( cLine, nPosi + 3 )
nPosi := AT( ",", cNext )
IF nPosi > 0
cDD := LTRIM( SUBSTR( cNext, 1, nPosi - 1 ) )
cYear := LTRIM( SUBSTR( cNext, nPosi + 1 ) )
cYYYY := SUBSTR( cYear, 1, 4 )
cMore := SUBSTR( cYear, 5 )
IF "pm" $ cMore
nPosi := AT( "pm", cMore )
cHHMMSS := SUBSTR( cMore, 1, nPosi - 1 )
nSec := HMS2SEC( cHHMMSS )
nSec += ( 12 * 60 * 60 )
cHHMMSS := SEC2HMS( nSec )
ELSE
nPosi := AT( "am", cMore )
cHHMMSS := SUBSTR( cMore, 1, nPosi - 1 )
nSec := HMS2SEC( cHHMMSS )
cHHMMSS := SEC2HMS( nSec )
ENDIF
ELSE
RETURN CTOD( " . . " )
ENDIF
ELSE
RETURN CTOD( " . . " )
ENDIF
cTime := cHHMMSS
RETURN STOD( cYYYY + cMM + cDD )
p.s.
HMS2SEC() and SEC2HMS() are to convert HH:MM:SS <-> Seconds
is there a harbour Function

Re: "Text" Date/Time to "Number" ?
Posted: Tue Aug 16, 2022 3:56 pm
by rhlawek
Not sure this is useful to anybody to me, but this is how I convert back and forth from harbour datetime to ISO datetime.
Code: Select all | Expand
// -------------------------------------------------------------------------- //
// DateTimeToISO8601( t )
FUNCTION hb_TToI( t )
hb_Default( @t, DateTime() )
t := hb_TToS( t )
RETURN SubStr( t, 01, 04 ) + "-" + ;
SubStr( t, 05, 02 ) + "-" + ;
SubStr( t, 07, 02 ) + "T" + ;
SubStr( t, 09, 02 ) + ":" + ;
SubStr( t, 11, 02 ) + ":" + ;
SubStr( t, 13, 02 ) + "." + ;
SubStr( t, 15, 03 )
// -------------------------------------------------------------------------- //
// IS8601ToDateTime
FUNCTION hb_IToT( cISO )
IF Empty( cISO )
RETURN _EMPTY_DATETIME
ENDIF
RETURN hb_DateTime( Val( SubStr( cISO, 01, 04 ) ), ;
Val( SubStr( cISO, 06, 02 ) ), ;
Val( SubStr( cISO, 09, 02 ) ), ;
Val( SubStr( cISO, 12, 02 ) ), ;
Val( SubStr( cISO, 15, 02 ) ), ;
Val( SubStr( cISO, 18, 02 ) ), ;
Val( SubStr( cISO, 21, 03 ) ) )
Re: "Text" Date/Time to "Number" ?
Posted: Tue Aug 16, 2022 6:25 pm
by nageswaragunupudi
Code: Select all | Expand
Secs( <cTimeStr> / <tDateTime> ) --> nSecs
TimeToSec( <cTimeStr> ) --> nSecs
TString( nSecs ) --> cTimeStr
SecToTime( [<nSeconds>], [<lHundredth>] ) --> cTime
Re: "Text" Date/Time to "Number" ?
Posted: Tue Aug 16, 2022 7:28 pm
by rhlawek
Thanks Rao. The secs() function in harbour actually gets mapped to hb_sec() in dateshb.c, which took me a few minutes to find. But I see a bunch of potentially useful functions there now that I'm going to test to see if I can get rid of the code I'm currently using and revert to native harbour.
Robb
Re: "Text" Date/Time to "Number" ?
Posted: Tue Aug 16, 2022 8:09 pm
by nageswaragunupudi
rhlawek wrote:Not sure this is useful to anybody to me, but this is how I convert back and forth from harbour datetime to ISO datetime.
Code: Select all | Expand
// -------------------------------------------------------------------------- //
// DateTimeToISO8601( t )
FUNCTION hb_TToI( t )
hb_Default( @t, DateTime() )
t := hb_TToS( t )
RETURN SubStr( t, 01, 04 ) + "-" + ;
SubStr( t, 05, 02 ) + "-" + ;
SubStr( t, 07, 02 ) + "T" + ;
SubStr( t, 09, 02 ) + ":" + ;
SubStr( t, 11, 02 ) + ":" + ;
SubStr( t, 13, 02 ) + "." + ;
SubStr( t, 15, 03 )
// -------------------------------------------------------------------------- //
// IS8601ToDateTime
FUNCTION hb_IToT( cISO )
IF Empty( cISO )
RETURN _EMPTY_DATETIME
ENDIF
RETURN hb_DateTime( Val( SubStr( cISO, 01, 04 ) ), ;
Val( SubStr( cISO, 06, 02 ) ), ;
Val( SubStr( cISO, 09, 02 ) ), ;
Val( SubStr( cISO, 12, 02 ) ), ;
Val( SubStr( cISO, 15, 02 ) ), ;
Val( SubStr( cISO, 18, 02 ) ), ;
Val( SubStr( cISO, 21, 03 ) ) )
I think these functions can be simplified like this:
Code: Select all | Expand
function ISO2DateTime( cDate )
local df := Set( _SET_DATEFORMAT, "YYYY-MM-DD" )
local tf := Set( _SET_TIMEFORMAT, "HH:MM:SS.fff" )
local tDateTime := HB_CTOT( cDate )
Set( _SET_DATEFORMAT, df )
Set( _SET_TIMEFORMAT, tf )
return tDateTime
function DateTime2ISO( tDateTime )
local df := Set( _SET_DATEFORMAT, "YYYY-MM-DD" )
local tf := Set( _SET_TIMEFORMAT, "HH:MM:SS.fff" )
local cDate := StrTran( HB_TTOC( tDateTime ), " ", "T" )
Set( _SET_DATEFORMAT, df )
Set( _SET_TIMEFORMAT, tf )
return cDate