Appearance
LuaDateTime
Representa una fecha y hora. Se obtiene al llamar a get_date_time() o al leer un campo DateTime desde un ResultSet.
Conversión a string
lua
tostring(dt) -- → "2024-01-15T14:30:00"
"" .. dt -- → "2024-01-15T14:30:00"Función global
get_date_time()
Obtiene la fecha y hora actuales.
lua
local dt = get_date_time()Creación
lua
local dt = get_date_time()
-- Desde función global con año, mes, día, hora, minuto, segundo
local evento = date_time(2026, 6, 7, 15, 30, 0)Métodos de acceso
lua
dt:year() -- → 2026 (int)
dt:month() -- → 6 (int)
dt:day() -- → 7 (int)
dt:hour() -- → 0-23 (int)
dt:minute() -- → 0-59 (int)
dt:second() -- → 0-59 (int)
dt:day_of_week() -- → "domingo"
dt:day_of_week_number() -- → 1-7 (int)Formato
lua
dt:format() -- → "15/01/2024 14:30" (según cultura de la app)
dt:format("yyyy-MM-dd HH:mm:ss") -- → "2024-01-15 14:30:00"
dt:format("dd MMM yyyy HH:mm", "es-AR") -- → "15 ene. 2024 14:30"El formato sigue los patrones de formato de fecha y hora de .NET.
Extraer fecha u hora
lua
dt:date() -- → LuaDate
dt:time() -- → LuaTimeOperaciones
lua
-- Diferencia entre fechas (en días)
dt:days_between(otro_dt) -- → int
-- Sumar/restar unidades
dt:add(2, "hours") -- → LuaDateTime
dt:add(7, "days") -- (también "months", "years", "minutes", "seconds")
-- Redondear a un intervalo
dt:round(15, "minutes") -- → LuaDateTime, redondea al cuarto de hora
dt:round(1, "hours") -- → LuaDateTime, redondea a la hora exacta
dt:round(7, "days") -- → LuaDateTime, redondea al día 7, 14, 21 o 28
dt:round(3, "months") -- → LuaDateTime, redondea al inicio del trimestre
dt:round(1, "months", "floor") -- → LuaDateTime, redondea hacia abajo (inicio del mes)
dt:round(30, "minutes", "ceil") -- → LuaDateTime, redondea hacia arribaSoporta unidades: seconds, minutes, hours, days, months, years.
Modo de redondeo (opcional): "round" (defecto, redondeo estándar), "floor" (siempre hacia abajo), "ceil" (siempre hacia arriba).