Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Error en DateTimePicker (https://www.clubdelphi.com/foros/showthread.php?t=91858)

oscarac 19-05-2017 23:57:54

Error en DateTimePicker
 
buenas tardes
tengo esta rutina
Código Delphi [-]
Function Establecerfechas (var dtInicio:TDate; var dtFinal:TDate; mInicial :Integer):Boolean;
Var t_dia, t_mes, t_ano : String; t_mes1 :Integer;
begin
  if mInicial = 0 then
    t_mes := dmGlobal.g_Mes
  else
    t_mes := Llenar(IntToStr(mInicial),2);

  t_dia := '01';
  t_ano := Copy (dmGlobal.g_Periodo,1,4);
  dtInicio := StrToDate(t_dia + '/' + t_mes + '/' + t_ano);

  t_dia := '01';
  t_mes1 := StrToInt(dmGlobal.g_Mes) + 1;

  If dmGlobal.g_Mes <= '11' then
   dtFinal := Trunc(StrToDate(t_dia + '/' + IntToStr(t_mes1) + '/' + t_ano) -1)
  else
   dtFinal := Trunc(StrToDate( '31/12/' + Copy(dmGlobal.g_periodo,1,4)));

Result := True;
End;

Donde:
dmGlobal.g_MES = variable publica que me guarda el mes del año que estoy procesando
Llenar(IntToStr(mInicial),2) // Llena de ceros Osea de '1' pasa a ser '01'
dmGlobal.g_periodo = variable publica que tiene el año y mes en proceso ejemplo '200801' Año 2018 Mes Enero
para no hacerles el cuento largo lo que hace la rutina es basicamente encontrar el primer dia del mes y el ultimo dia del mes

Uso TDateTimePicker
y en algun momento invoco a la rutina asi

Código Delphi [-]
Var dtInicio , dtFin : TDate;
begin
  Establecerfechas(dtinicio, dtFin, 0);
  dtFechaVoucher.MinDate := dtInicio;
  dtFechaVoucher.MaxDate := dtFin;

pero cuando quiero cambiar la fecha me aparece este mensaje :

Cita:

Failed to Set Calendar date or time
solo sucede cuando se trata de establecer la fecha minima y maxima, en los demas casos no hay problema

Caminante 20-05-2017 15:31:43

Hola

Si solo es encontrar el primer y ultimo dia del mes de una fecha dada yo hago esto:

Código Delphi [-]
var
  Finicio,FFinal,Fecha:TDate;
begin
  Fecha:=date;
  finicio:=encodedate(YearOf(fecha),MonthOf(fecha),1);
  ffinal:=encodedate(yearof(fecha),MonthOf(fecha),DaysInMonth(fecha));
  showmessage(datetostr(fecha) +#13 +DateToStr(finicio) + #13+ datetostr(ffinal))
end;

Debes incluir la unidad dateutils.

Espero te sea util

Saludos

oscarac 21-05-2017 18:04:38

Voy a probar
Gracias


La franja horaria es GMT +2. Ahora son las 13:12:13.

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