Whatever message this page gives is out now! Go check it out!
DateAdd(datepart, number, date)Parameter | Description |
datepart | String:
|
number | Number of units of datepart to add to date (positive, to get dates in the future; negative, to get dates in the past). Number must be an integer. |
date | Date/time object, in the range 100 AD-9999 AD. |
<cfscript>
date="{ts '2433-09-01 23:59:59'}";
writeOutput("#date#");
diff=30;
posdateresult=DateAdd("s",diff,date);
writeOutput("#posdateresult#");
</cfscript><cfscript>
writeOutput("<h2>1. E-Commerce Subscription Renewal System</h2>");
// Customer subscription start date
subscriptionStart = now();
// Different subscription types with their renewal periods
subscriptionPlans = [
{name: "Monthly Premium", period: "m", duration: 1},
{name: "Quarterly Business", period: "q", duration: 1},
{name: "Annual Enterprise", period: "yyyy", duration: 1},
{name: "Weekly Trial", period: "ww", duration: 1}
];
writeOutput("<p><strong>Subscription Start Date:</strong> " & dateFormat(subscriptionStart, "mm/dd/yyyy") & " " & timeFormat(subscriptionStart, "HH:mm:ss") & "</p>");
writeOutput("<table border='1' cellpadding='5'>");
writeOutput("<tr><th>Plan Type</th><th>Duration</th><th>Renewal Date</th><th>Days Until Renewal</th></tr>");
for (plan in subscriptionPlans) {
renewalDate = dateAdd(plan.period, plan.duration, subscriptionStart);
daysUntilRenewal = dateDiff("d", subscriptionStart, renewalDate);
writeOutput("<tr>");
writeOutput("<td>" & plan.name & "</td>");
writeOutput("<td>" & plan.duration & " " & plan.period & "</td>");
writeOutput("<td>" & dateFormat(renewalDate, "mm/dd/yyyy") & "</td>");
writeOutput("<td>" & daysUntilRenewal & " days</td>");
writeOutput("</tr>");
}
writeOutput("</table><br>");
// Calculate grace period (7 days after renewal)
monthlyRenewal = dateAdd("m", 1, subscriptionStart);
gracePeriodEnd = dateAdd("d", 7, monthlyRenewal);
writeOutput("<p><strong>Grace Period Example:</strong> Monthly renewal on " & dateFormat(monthlyRenewal, "mm/dd/yyyy") & " with grace period ending " & dateFormat(gracePeriodEnd, "mm/dd/yyyy") & "</p>");
</cfscript><cfscript>
writeOutput("<hr><h2>2. Project Management Timeline Calculator</h2>");
projectStartDate = createDate(2024, 1, 15); // Monday
// Project phases with business day durations
projectPhases = [
{phase: "Requirements Gathering", businessDays: 5},
{phase: "Design & Architecture", businessDays: 10},
{phase: "Development Sprint 1", businessDays: 15},
{phase: "Development Sprint 2", businessDays: 15},
{phase: "Testing & QA", businessDays: 8},
{phase: "Deployment & Launch", businessDays: 3}
];
writeOutput("<p><strong>Project Start Date:</strong> " & dateFormat(projectStartDate, "mm/dd/yyyy") & " (" & dayOfWeekAsString(dayOfWeek(projectStartDate)) & ")</p>");
writeOutput("<table border='1' cellpadding='5'>");
writeOutput("<tr><th>Phase</th><th>Business Days</th><th>Start Date</th><th>End Date</th><th>Day of Week</th></tr>");
currentDate = projectStartDate;
for (phase in projectPhases) {
phaseStart = currentDate;
// Add business days (multiply by 1.4 to account for weekends approximately)
// More precise method would check each day, but this gives a good estimate
totalDays = ceiling(phase.businessDays * 1.4);
phaseEnd = dateAdd("d", totalDays, phaseStart);
// Adjust if it falls on weekend
while (dayOfWeek(phaseEnd) == 1 OR dayOfWeek(phaseEnd) == 7) {
phaseEnd = dateAdd("d", 1, phaseEnd);
}
writeOutput("<tr>");
writeOutput("<td>" & phase.phase & "</td>");
writeOutput("<td>" & phase.businessDays & "</td>");
writeOutput("<td>" & dateFormat(phaseStart, "mm/dd/yyyy") & "</td>");
writeOutput("<td>" & dateFormat(phaseEnd, "mm/dd/yyyy") & "</td>");
writeOutput("<td>" & dayOfWeekAsString(dayOfWeek(phaseEnd)) & "</td>");
writeOutput("</tr>");
currentDate = dateAdd("d", 1, phaseEnd); // Next phase starts day after
}
writeOutput("</table><br>");
// Calculate project completion
finalDate = dateAdd("d", -1, currentDate);
projectDuration = dateDiff("d", projectStartDate, finalDate);
writeOutput("<p><strong>Total Project Duration:</strong> " & projectDuration & " calendar days</p>");
</cfscript><cfscript>
writeOutput("<hr><h2>3. Financial Payment Scheduling System</h2>");
// Loan details
loanAmount = 50000;
loanStartDate = createDate(2024, 1, 1);
monthlyPayment = 1250;
writeOutput("<p><strong>Loan Details:</strong></p>");
writeOutput("<ul>");
writeOutput("<li>Loan Amount: " & dollarFormat(loanAmount) & "</li>");
writeOutput("<li>Monthly Payment: " & dollarFormat(monthlyPayment) & "</li>");
writeOutput("<li>Start Date: " & dateFormat(loanStartDate, "mm/dd/yyyy") & "</li>");
writeOutput("</ul>");
writeOutput("<h3>Payment Schedule (First 12 months)</h3>");
writeOutput("<table border='1' cellpadding='5'>");
for (i = 1; i <= 12; i++) {
paymentDate = dateAdd("m", i, loanStartDate);
daysFromStart = dateDiff("d", loanStartDate, paymentDate);
writeOutput("<tr>");
writeOutput("<td>" & i & "</td>");
writeOutput("<td>" & dateFormat(paymentDate, "mm/dd/yyyy") & "</td>");
writeOutput("<td>$" & dollarFormat(monthlyPayment) & "</td>");
writeOutput("<td>" & daysFromStart & "</td>");
writeOutput("</tr>");
}
writeOutput("</table><br>");
// Calculate different payment frequencies
writeOutput("<h3>Alternative Payment Frequencies</h3>");
paymentTypes = [
{type: "Weekly", period: "ww", multiplier: 1, amount: 288},
{type: "Bi-Weekly", period: "ww", multiplier: 2, amount: 577},
{type: "Quarterly", period: "q", multiplier: 1, amount: 3750},
{type: "Semi-Annual", period: "m", multiplier: 6, amount: 7500}
];
writeOutput("<table border='1' cellpadding='5'>");
writeOutput("<tr><th>Payment Type</th><th>Next Due Date</th><th>Amount</th><th>Following Date</th></tr>");
for (payment in paymentTypes) {
nextDue = dateAdd(payment.period, payment.multiplier, loanStartDate);
followingDue = dateAdd(payment.period, payment.multiplier, nextDue);
writeOutput("<tr>");
writeOutput("<td>" & payment.type & "</td>");
writeOutput("<td>" & dateFormat(nextDue, "mm/dd/yyyy") & "</td>");
writeOutput("<td>$" & dollarFormat(payment.amount) & "</td>");
writeOutput("<td>" & dateFormat(followingDue, "mm/dd/yyyy") & "</td>");
writeOutput("</tr>");
}
writeOutput("</table><br>");
</cfscript><cfscript>
writeOutput("<hr><h2>4. Event Management & Reminder System</h2>");
// Main event details
eventDate = createDateTime(2024, 6, 15, 14, 30, 0); // June 15, 2024, 2:30 PM
eventName = "Annual Company Conference";
writeOutput("<p><strong>Event:</strong> " & eventName & "</p>");
writeOutput("<p><strong>Event Date & Time:</strong> " & dateFormat(eventDate, "mm/dd/yyyy") & " at " & timeFormat(eventDate, "h:mm tt") & "</p>");
// Calculate reminder schedule
reminderSchedule = [
{name: "Save the Date", days: -90, timeUnit: "d"},
{name: "Early Bird Registration", days: -60, timeUnit: "d"},
{name: "Final Registration Reminder", days: -30, timeUnit: "d"},
{name: "One Week Notice", days: -7, timeUnit: "d"},
{name: "Day Before Reminder", days: -1, timeUnit: "d"},
{name: "Day of Event - Morning", hours: -4, timeUnit: "h"},
{name: "Event Starts Soon", minutes: -30, timeUnit: "n"}
];
writeOutput("<h3>Automated Reminder Schedule</h3>");
writeOutput("<table border='1' cellpadding='5'>");
writeOutput("<tr><th>Reminder Type</th><th>Send Date</th><th>Send Time</th><th>Days Until Event</th></tr>");
for (reminder in reminderSchedule) {
if (structKeyExists(reminder, "days")) {
reminderDate = dateAdd(reminder.timeUnit, reminder.days, eventDate);
} else if (structKeyExists(reminder, "hours")) {
reminderDate = dateAdd(reminder.timeUnit, reminder.hours, eventDate);
} else if (structKeyExists(reminder, "minutes")) {
reminderDate = dateAdd(reminder.timeUnit, reminder.minutes, eventDate);
}
daysUntilEvent = dateDiff("d", reminderDate, eventDate);
writeOutput("<tr>");
writeOutput("<td>" & reminder.name & "</td>");
writeOutput("<td>" & dateFormat(reminderDate, "mm/dd/yyyy") & "</td>");
writeOutput("<td>" & timeFormat(reminderDate, "h:mm tt") & "</td>");
writeOutput("<td>" & daysUntilEvent & "</td>");
writeOutput("</tr>");
}
writeOutput("</table><br>");
// Multi-day event scheduling
writeOutput("<h3>Multi-Day Conference Schedule</h3>");
conferenceDays = [
{day: "Pre-Conference Workshop", dayOffset: -1, startTime: "09:00"},
{day: "Main Conference Day 1", dayOffset: 0, startTime: "08:30"},
{day: "Main Conference Day 2", dayOffset: 1, startTime: "08:30"},
{day: "Post-Conference Networking", dayOffset: 2, startTime: "18:00"}
];
writeOutput("<table border='1' cellpadding='5'>");
writeOutput("<tr><th>Event Day</th><th>Date</th><th>Start Time</th><th>Day of Week</th></tr>");
for (day in conferenceDays) {
dayDate = dateAdd("d", day.dayOffset, eventDate);
writeOutput("<tr>");
writeOutput("<td>" & day.day & "</td>");
writeOutput("<td>" & dateFormat(dayDate, "mm/dd/yyyy") & "</td>");
writeOutput("<td>" & day.startTime & "</td>");
writeOutput("<td>" & dayOfWeekAsString(dayOfWeek(dayDate)) & "</td>");
writeOutput("</tr>");
}
writeOutput("</table><br>");
</cfscript>