Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Rescatar ultimo dia de un mes (https://www.clubdelphi.com/foros/showthread.php?t=87091)

BPL 12-11-2014 20:02:50

Rescatar ultimo dia de un mes
 
Hola a Todos,
Necesito, saber si existe algún componente o rutina para rescatar el ultimo día de un mes dado...

gracias, a quien pueda ayudarme...

roman 12-11-2014 20:35:41

¿Por rescatar te refieres a obtener?

Supongo que si tomas el primer día del siguiente mes y le restas un día, obtienes lo que quieres.

// Saludos

duilioisola 13-11-2014 13:38:55

Si es OBTENER, como dice roman...

De la ayuda de Delphi 6:

Cita:

DaysInAMonth function
Returns the number of days in a specified month of a specified year.

Unit
DateUtils

Category
date/time routines

function DaysInAMonth(const AYear, AMonth: Word): Word;

Description
Call DaysInAMonth to obtain the number of days in the specified month of the specified year.
AYear is a year between 1 and 9999 (inclusive).
AMonth is a month between 1 and 12 (inclusive).
En DelphiBasics

Código Delphi [-]
begin
  // How many days in February 2000 ?
   ShowMessage('Days in February 2000 = '+
               IntToStr(DaysInAMonth(2000, 2)));
end;

ecfisa 13-11-2014 14:19:45

Hola BPL.

Y si deseas mostrar el nombre y número del día,
Código Delphi [-]
uses DateUtils;

function LastDay(const aMonth, aYear: Word): string;
const
  NDAY: array[1..7] of string = ('lunes','martes','miercoles','jueves','viernes','sabado','domingo');
var
  LastDay: Word;
  dt: TDate;
begin
  LastDay:= DaysInMonth(EncodeDate(aYear, aMonth, 1));
  dt:= EncodeDate(aYear, aMonth, LastDay);
  Result:= Format('%s %d',[NDAY[DayOfTheWeek(dt)], LastDay]);
end;

Código Delphi [-]
begin
  ShowMessage(LastDay(2, 2008))
end;

Saludos :)

roman 13-11-2014 17:59:25

A ver esta:

Código Delphi [-]
function LastDay(Year, Month: Integer): TDate;
begin
  Result := EncodeDate(Year + (Month div 12), (Month mod 12) + 1, 1) - 1;
end;

// Saludos


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

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