API ReferenceQuery
isToday()
Check if a date is today. Simple and efficient method for highlighting current day, filtering today's events, and building calendar applications.
Checks if this date is today (same calendar day as the current date).
Syntax
.isToday(): booleanReturns
boolean - True if the date is today
Examples
Basic Usage
import { fdu } from "@pyyupsk/fdu";
// Assuming today is 2024-01-15
fdu("2024-01-15").isToday(); // true
fdu("2024-01-15T23:59:59").isToday(); // true (same day, different time)
fdu("2024-01-14").isToday(); // false
fdu("2024-01-16").isToday(); // falseCurrent Date Check
fdu().isToday(); // always true (current moment)Highlight Today in Calendar
function renderCalendarDay(date: FduInstance) {
const isCurrentDay = date.isToday();
return {
date: date.format("D"),
className: isCurrentDay ? "today highlight" : "day",
};
}Filter Today's Events
const events = [
{ date: fdu("2024-01-14"), title: "Yesterday's Meeting" },
{ date: fdu("2024-01-15"), title: "Today's Meeting" },
{ date: fdu("2024-01-16"), title: "Tomorrow's Meeting" },
];
// Assuming today is 2024-01-15
const todaysEvents = events.filter((e) => e.date.isToday());
// [{ date: ..., title: "Today's Meeting" }]Daily Task Reminder
function shouldRemind(taskDueDate: FduInstance): boolean {
return taskDueDate.isToday() || taskDueDate.isBefore(fdu(), "day");
}
const task = { dueDate: fdu("2024-01-15"), title: "Submit report" };
shouldRemind(task.dueDate); // true if today or overdueDisplay Relative Date Label
function getDateLabel(date: FduInstance): string {
if (date.isToday()) return "Today";
if (date.isTomorrow()) return "Tomorrow";
if (date.isYesterday()) return "Yesterday";
return date.format("MMM D, YYYY");
}
getDateLabel(fdu()); // "Today"
getDateLabel(fdu().add(1, "day")); // "Tomorrow"
getDateLabel(fdu().subtract(1, "day")); // "Yesterday"
getDateLabel(fdu("2024-12-25")); // "Dec 25, 2024"See Also
- isTomorrow() - Check if date is tomorrow
- isYesterday() - Check if date is yesterday
- isSame() - Compare dates at specific granularity
diff()
Learn how to calculate differences between dates using the diff() method. Calculate age, duration, time elapsed, and date differences in years, months, weeks, days, hours, minutes, seconds, and milliseconds with practical examples for deadline warnings, relative time, working hours, and subscription duration tracking.
isTomorrow()
Check if a date is tomorrow. Useful for upcoming event notifications, deadline warnings, and scheduling applications.