"Text" Date/Time to "Number" ?

"Text" Date/Time to "Number" ?

Postby Jimmy » Sun Aug 14, 2022 8:30 am

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
&raquo; Thu Oct 06, 2005 6:24 pm </p>
&raquo; Thu Oct 06, 2005 8:28 pm </p>
&raquo; Fri Oct 07, 2005 7:11 pm </p>
&raquo; Sun Feb 26, 2006 9:17 am </p>

how can i convert those Date/Time String into his Format :?:
Code: Select all  Expand view  RUN
YYYY-MM-DD HH:MM:SS
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: "Text" Date/Time to "Number" ?

Postby cnavarro » Sun Aug 14, 2022 9:59 am

Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: "Text" Date/Time to "Number" ?

Postby Jimmy » Sun Aug 14, 2022 5:20 pm

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
Code: Select all  Expand view  RUN
  SET DATE ANSI
   SET CENTURY ON
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: "Text" Date/Time to "Number" ?

Postby nageswaragunupudi » Mon Aug 15, 2022 9:00 am

Do you wan to convert the string "&raquo; 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?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: "Text" Date/Time to "Number" ?

Postby Jimmy » Mon Aug 15, 2022 7:36 pm

hi,
nageswaragunupudi wrote:Do you wan to convert the string "&raquo; 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 view  RUN
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( "&raquo;", cLine )
   IF nPosi > 0
      cLine := SUBSTR( cLine, nPosi + 7 )
   ELSE
      RETURN CTOD( " . . " )
   ENDIF

   //  &raquo; 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 :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: "Text" Date/Time to "Number" ?

Postby rhlawek » Tue Aug 16, 2022 3:56 pm

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 view  RUN

// -------------------------------------------------------------------------- //

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



 
User avatar
rhlawek
 
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm

Re: "Text" Date/Time to "Number" ?

Postby nageswaragunupudi » Tue Aug 16, 2022 6:25 pm

Code: Select all  Expand view  RUN
Secs( <cTimeStr> / <tDateTime> ) --> nSecs
TimeToSec( <cTimeStr> ) --> nSecs


TString( nSecs ) --> cTimeStr
SecToTime( [<nSeconds>], [<lHundredth>] ) --> cTime
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: "Text" Date/Time to "Number" ?

Postby rhlawek » Tue Aug 16, 2022 7:28 pm

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
User avatar
rhlawek
 
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm

Re: "Text" Date/Time to "Number" ?

Postby nageswaragunupudi » Tue Aug 16, 2022 8:09 pm

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 view  RUN

// -------------------------------------------------------------------------- //

// 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 view  RUN
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
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 76 guests