MySQL: datetime
Moderador: Moderadores
MySQL: datetime
Pessoal,
Estou tentando usar o campo datetime no MySQL via Harbour, mas estou tendo dificuldade para tratar o campo no Harbour. Não consigo descobrir qual é o tipo de campo no Harbour.
Testei type(campo), dá erro.
Testei valtype(campo), retorna T. Não achei esse tipo de campo no NG.
Testei usar esse campo como caractere, dá erro.
Testei usar ctod(campo), também dá erro.
Alguém poderia me ajudar, por favor?
Estou tentando usar o campo datetime no MySQL via Harbour, mas estou tendo dificuldade para tratar o campo no Harbour. Não consigo descobrir qual é o tipo de campo no Harbour.
Testei type(campo), dá erro.
Testei valtype(campo), retorna T. Não achei esse tipo de campo no NG.
Testei usar esse campo como caractere, dá erro.
Testei usar ctod(campo), também dá erro.
Alguém poderia me ajudar, por favor?
Inacio de Carvalho Neto
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MySQL: datetime
Pois é, há vários tipos que não encontra no NG, porque NG é pra CLIPPER.cjp escreveu:Testei valtype(campo), retorna T. Não achei esse tipo de campo no NG.
T é justamente campo datetime
Tem também incremental e outros.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
- Itamar M. Lins Jr.
- Administrador

- Mensagens: 7928
- Registrado em: 30 Mai 2007 11:31
- Localização: Ilheus Bahia
- Curtiu: 1 vez
MySQL: datetime
Olá!
Complementando.
>hbmk2 -find hb_tt
Campo Timestamp conversão.
E tem gente que pensa que Harbour é só clipper para 32 bits.
Saudações,
Itamar M. Lins Jr.
Complementando.
>hbmk2 -find hb_tt
Código: Selecionar todos
itamar@itamar-desktop:~$ hbmk2 -find hb_tt
Núcleo Harbour (instalado):
hb_TToC()
hb_TToD()
hb_TToHour()
hb_TToMin()
hb_TToMSec()
hb_TToN()
hb_TToS()
hb_TToSec()
E tem gente que pensa que Harbour é só clipper para 32 bits.
Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Itamar M. Lins Jr.
- JoséQuintas
- Administrador

- Mensagens: 20267
- Registrado em: 26 Fev 2007 11:59
- Localização: São Paulo-SP
MySQL: datetime
Mais tipos
Harbour extended Field Types
D Date 3, 4 or 8 Date
M Memo 4 or 8 Memo
+ AutoInc 4 Auto increment
= ModTime 8 Last modified date & time of this record
^ RowVers 8 Row version number; modification count of this record
@ DayTime 8 Date & Time
I Integer 1, 2, 3, 4 or 8 Signed Integer ( Width : )" },;
T Time 4 or 8 Only time (if width is 4 ) or Date & Time (if width is 8 ) (?)
V Variant 3, 4, 6 or more Variable type Field
Y Currency 8 64 bit integer with implied 4 decimal
B Double 8 Floating point / 64 bit binary
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"
https://github.com/JoseQuintas/
MySQL: datetime
Entendi.
Só resta a dúvida de como exatamente tratar esse campo no Harbour. Ele não é texto, não é data... como faço para convertê-lo num texto?
Só resta a dúvida de como exatamente tratar esse campo no Harbour. Ele não é texto, não é data... como faço para convertê-lo num texto?
Inacio de Carvalho Neto
-
alxsts
- Colaborador

- Mensagens: 3092
- Registrado em: 12 Ago 2008 15:50
- Localização: São Paulo-SP-Brasil
MySQL: datetime
Olá!
Harbour extension to the Date() function that returns a date value from the supplied day, month and year values. If any of them is invalid or missing, an empty date is returned. If none of them is supplied, the current date is returned.
o hb_DateTime([<nYear>, <nMonth>, <nDay>, <nHour>, <nMinute>, <nSecond>, <nFragment>]) ➜ tTimeStamp
Returns a timestamp value from the supplied day, month, year, hour, minute, second and second-fragment values. If none of them is supplied, the current date and time is returned.
o hb_DtoC(<dDate>|<tTimeStamp> [, <cDateFormat>]) ➜ cDate
Harbour extension to the DtoC() function. It converts a date value <dDate> (or the date value of <tTimeStamp>) to a string. If no date format is supplied the _SET_DATEFORMAT format will be used.
o hb_DtoT(<dDate> [, <cnTime>]) ➜ tTimeStamp
Returns a timestamp from the date and time values. <dDate> is a date value and <cnTime> is the time part and could be a number (as from Seconds()) or a string (as from Time()), (see time string format).
o hb_TSToStr( <tTimeStamp> [, <lPacked>] ) ➜ cTimeStamp
Returns <cTimeStamp> with the format YYYY-MM-DD hh:mm:ss.fff. If <lPacked> is .T. empty elements of the timestamp will be stripped out.
o hb_TSToUTC( [<tLocalTime>] ) ➜ tUtcTime
Converts a local time tTIMESTAMP to UTC time.
o hb_TtoC( <dDate>|<tTimeStamp> [, <cDateFormat>, <cTimeFormat>] ) ➜ cTimeStamp
Converts date or timestamp values to timestamp formatted strings.
o hb_TtoD( <dDate>|<tTimeStamp> [, @<nSeconds>|@<cTime>, @<cTimeFormat>] ) ➜ dDate
Extracts date and time information from a timestamp or date value. It returns the date part as a date value. If <@nSeconds> or @<cTime> parameter is passed by reference then it obtains either the number of seconds in given day specified by timestamp value or the time as time string. If no <cTimeFormat> passed, then _SET_TIMEFORMAT is used.
o hb_TtoN( <dDate>|<tTimeStamp> ) ➜ nValue
Converts a date or timestamp value to numeric value. The integer part of returned <nValue> is the date part represented as a Julian date value, and the decimal part is the time part represented as milliseconds from midnight.
NOTE: the returned nValue must not be confused with Unix time number, since they're totally different!
o hb_TtoS( <dDate>|<tTimeStamp> ) ➜ cDateTime
Converts a date or timestamp value to string formated as YYYYMMDDHHMMSSFFF.
o hb_TToHour( <tTimeStamp> ) ➜ nHours
o hb_TToMin ( <tTimeStamp> ) ➜ nMinutes
o hb_TToSec ( <tTimeStamp> ) ➜ nSeconds
o hb_TToMSec( <tTimeStamp> ) ➜ nMilliseconds
The above four functions calculate/convert the <tTimeStamp> timestamp value to hours, minutes, seconds and milliseconds respectively.
All but hb_TToMSec() functions return a floating point number, where the fractional part represents the rest (decimal remainder) of the conversion. The hb_TToMSec() function returns milliseconds as an integer value.
NOTE: they are new functions, available for use after 2016-12-15 12:51 UTC+0100 commit (they are not available in earlier Harbour versions).
Fonte:
Petewg/harbour-core
https://github.com/Petewg/harbour-core/wiki/hb_D
https://github.com/Petewg/harbour-core/wiki/hb_T
NewDateTimeFunctions
Código: Selecionar todos
Set Date British
? hb_Date() --> 24/05/2021
? Time() --> 16:37:12
? hb_DateTime() --> 24/05/2021 16:37:19.979 // Este formato é um timestamp. Em XML usa-se 24/05/2021T16:37:19.979
? hb_DtoT(hb_Date(), 82000 ) --> 24/05/2021 22:46:40.000o hb_Date([<nYear>, <nMonth>, <nDay>]) ➜ dDatecjp escreveu:como faço para convertê-lo num texto?
Harbour extension to the Date() function that returns a date value from the supplied day, month and year values. If any of them is invalid or missing, an empty date is returned. If none of them is supplied, the current date is returned.
o hb_DateTime([<nYear>, <nMonth>, <nDay>, <nHour>, <nMinute>, <nSecond>, <nFragment>]) ➜ tTimeStamp
Returns a timestamp value from the supplied day, month, year, hour, minute, second and second-fragment values. If none of them is supplied, the current date and time is returned.
o hb_DtoC(<dDate>|<tTimeStamp> [, <cDateFormat>]) ➜ cDate
Harbour extension to the DtoC() function. It converts a date value <dDate> (or the date value of <tTimeStamp>) to a string. If no date format is supplied the _SET_DATEFORMAT format will be used.
o hb_DtoT(<dDate> [, <cnTime>]) ➜ tTimeStamp
Returns a timestamp from the date and time values. <dDate> is a date value and <cnTime> is the time part and could be a number (as from Seconds()) or a string (as from Time()), (see time string format).
o hb_TSToStr( <tTimeStamp> [, <lPacked>] ) ➜ cTimeStamp
Returns <cTimeStamp> with the format YYYY-MM-DD hh:mm:ss.fff. If <lPacked> is .T. empty elements of the timestamp will be stripped out.
o hb_TSToUTC( [<tLocalTime>] ) ➜ tUtcTime
Converts a local time tTIMESTAMP to UTC time.
o hb_TtoC( <dDate>|<tTimeStamp> [, <cDateFormat>, <cTimeFormat>] ) ➜ cTimeStamp
Converts date or timestamp values to timestamp formatted strings.
o hb_TtoD( <dDate>|<tTimeStamp> [, @<nSeconds>|@<cTime>, @<cTimeFormat>] ) ➜ dDate
Extracts date and time information from a timestamp or date value. It returns the date part as a date value. If <@nSeconds> or @<cTime> parameter is passed by reference then it obtains either the number of seconds in given day specified by timestamp value or the time as time string. If no <cTimeFormat> passed, then _SET_TIMEFORMAT is used.
o hb_TtoN( <dDate>|<tTimeStamp> ) ➜ nValue
Converts a date or timestamp value to numeric value. The integer part of returned <nValue> is the date part represented as a Julian date value, and the decimal part is the time part represented as milliseconds from midnight.
NOTE: the returned nValue must not be confused with Unix time number, since they're totally different!
o hb_TtoS( <dDate>|<tTimeStamp> ) ➜ cDateTime
Converts a date or timestamp value to string formated as YYYYMMDDHHMMSSFFF.
o hb_TToHour( <tTimeStamp> ) ➜ nHours
o hb_TToMin ( <tTimeStamp> ) ➜ nMinutes
o hb_TToSec ( <tTimeStamp> ) ➜ nSeconds
o hb_TToMSec( <tTimeStamp> ) ➜ nMilliseconds
The above four functions calculate/convert the <tTimeStamp> timestamp value to hours, minutes, seconds and milliseconds respectively.
All but hb_TToMSec() functions return a floating point number, where the fractional part represents the rest (decimal remainder) of the conversion. The hb_TToMSec() function returns milliseconds as an integer value.
NOTE: they are new functions, available for use after 2016-12-15 12:51 UTC+0100 commit (they are not available in earlier Harbour versions).
Fonte:
Petewg/harbour-core
https://github.com/Petewg/harbour-core/wiki/hb_D
https://github.com/Petewg/harbour-core/wiki/hb_T
NewDateTimeFunctions
[]´s
Alexandre Santos (AlxSts)
Alexandre Santos (AlxSts)
MySQL: datetime
Tentei usar estas funções aqui, mas está dando undefined reference na compilação.
Preciso de alguma lib extra?
Estou usando o hb32.
Preciso de alguma lib extra?
Estou usando o hb32.
Inacio de Carvalho Neto
- Itamar M. Lins Jr.
- Administrador

- Mensagens: 7928
- Registrado em: 30 Mai 2007 11:31
- Localização: Ilheus Bahia
- Curtiu: 1 vez
MySQL: datetime
Olá!
Mostra a tela, mostra o código.
Saudações,
Itamar M. Lins Jr.
Cadê ?mas está dando undefined
Mostra a tela, mostra o código.
Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Itamar M. Lins Jr.
-
alxsts
- Colaborador

- Mensagens: 3092
- Registrado em: 12 Ago 2008 15:50
- Localização: São Paulo-SP-Brasil
MySQL: datetime
Olá!
alxsts escreveu:
NOTE: they are new functions, available for use after 2016-12-15 12:51 UTC+0100 commit (they are not available in earlier Harbour versions).
[]´s
Alexandre Santos (AlxSts)
Alexandre Santos (AlxSts)
MySQL: datetime
De fato, a versão que eu estou usando deve ser anterior mesmo, pois já a uso há bastante tempo.
Testei agora com uma versão do hb 3.4 que tenho instalada, e funcionou. Vou ter algum trabalho para migrar meu sistema para esta versão, e também não sei se essa é a mais adequada, mas esta é outra questão.
O que ainda não entendi é o seguinte: como vou pegar o campo datetime do MySQL e pegar só a hora dele para usar no Harbour? Imagino que uma das funções que o Quintas citou faça isso, mas eu não consegui fazer.
Basicamente quero apenas pegar um campo da tabela MySQL que esteja, por exemplo, "2021-05-27 15:00:00", pegando apenas a hora (15:00) para trabalhar no Harbour como uma variável caratere.
Poderiam me ajudar?
Testei agora com uma versão do hb 3.4 que tenho instalada, e funcionou. Vou ter algum trabalho para migrar meu sistema para esta versão, e também não sei se essa é a mais adequada, mas esta é outra questão.
O que ainda não entendi é o seguinte: como vou pegar o campo datetime do MySQL e pegar só a hora dele para usar no Harbour? Imagino que uma das funções que o Quintas citou faça isso, mas eu não consegui fazer.
Basicamente quero apenas pegar um campo da tabela MySQL que esteja, por exemplo, "2021-05-27 15:00:00", pegando apenas a hora (15:00) para trabalhar no Harbour como uma variável caratere.
Poderiam me ajudar?
Inacio de Carvalho Neto
-
alxsts
- Colaborador

- Mensagens: 3092
- Registrado em: 12 Ago 2008 15:50
- Localização: São Paulo-SP-Brasil
MySQL: datetime
Olá!
Pode também trazer o valor DateTime do banco e extrair a hora com funções do Harbour...
Veja: MySQL Date and Time Functions
Você não precisa mudar para o 3.4 que, aliás, está parado há algum tempo. Apenas atualize o teu Harbour para a versão atual que é a 3.2. Eu uso a versão 3.2 Nightly e testei estas funções e funcionam.cjp escreveu:Vou ter algum trabalho para migrar meu sistema para esta versão, e também não sei se essa é a mais adequada, mas esta é outra questão.
Uma opção simples é:cjp escreveu:como vou pegar o campo datetime do MySQL e pegar só a hora dele para usar no Harbour?
Código: Selecionar todos
SELECT Right( Cast(now() as Varchar(16)), 5 ) -- Troque a função Now() pelo teu campo DateTimeVeja: MySQL Date and Time Functions
[]´s
Alexandre Santos (AlxSts)
Alexandre Santos (AlxSts)
MySQL: datetime
Poderia, por favor, me indicar qual o melhor lugar para baixar a versão indicada?
Testei no Heidisql o exemplo que vc mencionou, mas está dando erro (vide anexo). Fiz algo errado?
Testei no Heidisql o exemplo que vc mencionou, mas está dando erro (vide anexo). Fiz algo errado?
Inacio de Carvalho Neto
MySQL: datetime
A propósito, vendo o link citado, vi que a time() do MySQL resolve parte dos meus problemas.
Mas ainda preciso de uma função que trate o campo datetime no próprio Harbour.
Mas ainda preciso de uma função que trate o campo datetime no próprio Harbour.
Inacio de Carvalho Neto
-
alxsts
- Colaborador

- Mensagens: 3092
- Registrado em: 12 Ago 2008 15:50
- Localização: São Paulo-SP-Brasil
MySQL: datetime
Olá!
Sem querer ser indelicado, faço uma observação: nosso fórum é riquíssimo em informações relativas a xBase. Além disto, dispõe de um mecanismo de busca. Temos também o Google...
Veja o tópico: Instalação e configuração do Harbour - Win64cjp escreveu:Poderia, por favor, me indicar qual o melhor lugar para baixar a versão indicada?
Sem querer ser indelicado, faço uma observação: nosso fórum é riquíssimo em informações relativas a xBase. Além disto, dispõe de um mecanismo de busca. Temos também o Google...
Aqui, no MariaDB 10, normal, como mostrado acima. Informe qual banco de dados e respectiva versão usou para ver este erro. Use o comando:cjp escreveu:Testei no Heidisql o exemplo que vc mencionou, mas está dando erro (vide anexo). Fiz algo errado?
Código: Selecionar todos
SELECT Version()Esta tal função NÂO existe no próprio Harbour. Retorne (select) o campo datetime do banco em formato string ou o resultado da função Time(). Use sua criatividade e aplique as funções de tratamento de string do Harbour para obter o que precisa. Tem várias, além das funções de tratamento de data e hora): Substr(), Left(), Right()...cjp escreveu: A propósito, vendo o link citado, vi que a time() do MySQL resolve parte dos meus problemas..
Mas ainda preciso de uma função que trate o campo datetime no próprio Harbour.
[]´s
Alexandre Santos (AlxSts)
Alexandre Santos (AlxSts)
MySQL: datetime
Obrigado, vou instalar.Veja o tópico: Instalação e configuração do Harbour - Win64
Peço desculpas. De fato, eu respondi apressadamente, sem pesquisar antes.Sem querer ser indelicado, faço uma observação: nosso fórum é riquíssimo em informações relativas a xBase. Além disto, dispõe de um mecanismo de busca. Temos também o Google...
Então, aqui está o problema. O comando indicando está retornando a versão 5.6.49-log (vide anexo).Aqui, no MariaDB 10, normal, como mostrado acima. Informe qual banco de dados e respectiva versão usou para ver este erro. Use o comando:
Minha dúvida é: esta é a versão do MariaDB ou do MySQL? Porque o MariaDB aqui parecer ser o 10.4 (vide anexo).
O problema é que, com a versão que estou usando agora do Harbour, eu não consigo tratar a string que o select me retorna de forma alguma. Mas, atualizando o Harbour, espero resolver isso.Esta tal função NÂO existe no próprio Harbour. Retorne (select) o campo datetime do banco em formato string ou o resultado da função Time(). Use sua criatividade e aplique as funções de tratamento de string do Harbour para obter o que precisa. Tem várias, além das funções de tratamento de data e hora): Substr(), Left(), Right()...
Outro detalhe. Com este select:
Código: Selecionar todos
select online,time(online) as hora from numeros where id=1Mas, no Harbour, usando ADO, o mesmo select dá o "hora" com a string completa datetime (2021-05-28 00:41:14).
Isso também é por causa da versão do Harbour?
Inacio de Carvalho Neto
