"Text" Date/Time to "Number" ?

Post Reply
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

"Text" Date/Time to "Number" ?

Post 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
&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

YYYY-MM-DD HH:MM:SS
greeting,
Jimmy
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

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

Post by cnavarro »

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
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

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

Post 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

Code: Select all | Expand

  SET DATE ANSI
   SET CENTURY ON
greeting,
Jimmy
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

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

Post by nageswaragunupudi »

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
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

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

Post by Jimmy »

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

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

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

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



 
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

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

Post by nageswaragunupudi »

Code: Select all | Expand

Secs( <cTimeStr> / <tDateTime> ) --> nSecs
TimeToSec( <cTimeStr> ) --> nSecs


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

G. N. Rao.
Hyderabad, India
User avatar
rhlawek
Posts: 194
Joined: Sun Jul 22, 2012 7:01 pm

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

Post 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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

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

Post 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
 
Regards

G. N. Rao.
Hyderabad, India
Post Reply