Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Crear cadena aaaa-mm-ddThh:mm:ss (https://www.clubdelphi.com/foros/showthread.php?t=71470)

richy08 21-12-2010 00:51:51

Crear cadena aaaa-mm-ddThh:mm:ss
 
Buenas trades compañeros esoty tratando de crear la fecha con el formato
aaaa-mm-ddThh:mm:ss lo hago con el siguiente codigo
Código Delphi [-]
  MiFecha := now(); //07-05-09 23:37
  DecodeDate(MiFecha,Year,Month,Day);
  DecodeTime(MiFecha,Hour,Min,Sec,Msec);
 Fecha:= IntToStr(Year)+'-'+IntToStr(Month)+'-'+IntToStr(Day)+'T'+inttostr(Hour)+':'+inttostr(Min)+':'+inttostr(Sec);

pero dicho codigo tiene un error por que cuando una cifra es <9 al hacer el
inttostr(Sec) el 09 lo convierte a 9 ahi alguna funcion que me respete el 0 a la izquierda del 9

saludos

ecfisa 21-12-2010 01:05:44

Hola.

Se me ocurre que podés utilizar la función StringOfChar a ese efecto:
Código Delphi [-]
  Fecha:= IntToStr(Year)+'-'+IntToStr(Month)+'-'+IntToStr(Day)+' T '+
          IntToStr(Hour)+':'+IntToStr(Min)+':'+
          StringOfChar('0',2-Length(IntToStr(Sec)))+IntToStr(Sec);

Saludos.

richy08 21-12-2010 01:26:01

Cita:

Empezado por ecfisa (Mensaje 385505)
Hola.

Se me ocurre que podés utilizar la función StringOfChar a ese efecto:
Código Delphi [-] Fecha:= IntToStr(Year)+'-'+IntToStr(Month)+'-'+IntToStr(Day)+' T '+ IntToStr(Hour)+':'+IntToStr(Min)+':'+ StringOfChar('0',2-Length(IntToStr(Sec)))+IntToStr(Sec);


Saludos.

gracias ecfisa le voy a echar un ojo

saludos

Casimiro Notevi 21-12-2010 01:52:01

¿No te sirve FormatDateTime?

Código Delphi [-]
var
  cFecha : string;
begin
  cFecha := FormatDateTime('yyyy-mm-dd hh:nn:ss',now);

richy08 21-12-2010 17:16:58

Cita:

Empezado por Casimiro Notevi (Mensaje 385511)
¿No te sirve FormatDateTime?

Código Delphi [-]var cFecha : string;
begin cFecha := FormatDateTime('yyyy-mm-dd hh:nn:ss',now);

gracias por la respuesta pero creo que no por que como pongo laT dentro del formato??
yyyy-mm-ddThh:nn:ss

Casimiro Notevi 21-12-2010 18:02:56

Pues por ejemplo así:

Código Delphi [-]
var
  cFecha : string;
begin
  cFecha := formatdatetime('yyyy-mm-dd',now)+'T'+formatdatetime('hh:nn:ss',now);

Casimiro Notevi 21-12-2010 18:03:48

Y por cierto, ¿para qué sirve la 'T'?

richy08 21-12-2010 21:16:51

Cita:

Empezado por Casimiro Notevi (Mensaje 385566)
Y por cierto, ¿para qué sirve la 'T'?

gracias casimiro creo que esto si funcionara, a pues lo de la T es por que es requerimiento para la factura electronica que debe de ir en ese formato

saludos

maeyanes 21-12-2010 21:31:00

Hola...

Prueba así:

Código Delphi [-]
cFecha := FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', now);


Saludos...


La franja horaria es GMT +2. Ahora son las 05:51:05.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi