Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
First, THANK YOU for any help.

I have a date variable called Contract_End_Date and it is in the format of 11/18/23.

I need to set a 90 day reminder to renew before this date.

I need the output to be ddd.hh:mm:ss for the tool, I only care about the days as the hours, minutes and seconds are not as important so they can all be 0. It's just the days that really matter.

Note: Not sure if this matters, but this is for SpringCM aka Docusign CLM.

Here is what I have, but I am getting a "Console Error":
C#
// Given Contract_End_Date in MM/dd/yy format
string contractEndDateStr = "11/18/23";
DateTime contractEndDate = DateTime.ParseExact(contractEndDateStr, "MM/dd/yy", null);

// Calculate 90-day reminder
DateTime reminderDate = contractEndDate.AddDays(-90);

// Format the reminder as "ddd.hh:mm:ss"
string reminderFormatted = $"{(reminderDate - DateTime.MinValue).Days:D3}.00:00:00";

Console.WriteLine("90-Day Reminder: " + reminderFormatted);


What I have tried:

Thank you for your help! I am working on taking a C# course, I can read and edit, but some of the writing from scratch is not easy for me.
Posted
Updated 13-Sep-23 6:43am
v3
Comments
PIEBALDconsult 29-Aug-23 19:27pm    
Rule one: Do not store dates as strings.
Joel 2023 29-Aug-23 19:29pm    
Here is what I have but I am getting a "Console Error"
// Given Contract_End_Date in MM/dd/yy format
string contractEndDateStr = "11/18/23";
DateTime contractEndDate = DateTime.ParseExact(contractEndDateStr, "MM/dd/yy", null);

// Calculate 90-day reminder
DateTime reminderDate = contractEndDate.AddDays(-90);

// Format the reminder as "ddd.hh:mm:ss"
string reminderFormatted = $"{(reminderDate - DateTime.MinValue).Days:D3}.00:00:00";

Console.WriteLine("90-Day Reminder: " + reminderFormatted);
PIEBALDconsult 29-Aug-23 20:26pm    
So, use the Improve question button and add that to the question.
Dave Kreskowiak 29-Aug-23 20:31pm    
This doesn't make sense. Why would you need the difference in dates to be in ddd.hh:mm:ss format when you explicitly remove the time from your dates?

Also, typically, you would add -3 months, not -90 days. Yes, there is a difference.

You could just get the difference between the dates and the result would be a TimeSpan, which when printed, will give you the format you say you're looking for.
DateTime contractEndDate = ...
DateTime reminderDate = contractEndDate.AddMonths(-3);
TimeSpan difference = contractEndDate - reminderDate;
Console.WriteLine($"{difference}");
Richard Deeming 30-Aug-23 3:47am    
Why would you want to show the number of days between 1st January 0001 and the reminder date? That doesn't make any sense. Even if it worked, it wouldn't account for the switch-over from the Julian to the Gregorian calendar, so the value would be meaningless.

Did you mean to subtract the current date instead of the minimum date?

1 solution

C#
// Given Contract_End_Date in MM/dd/yy format
string contractEndDateStr = "11/18/23";
DateTime contractEndDate = DateTime.ParseExact(contractEndDateStr, "MM/dd/yy", null);

// Calculate 90-day reminder
DateTime reminderDate = contractEndDate.AddDays(-90);

// Format the reminder as "ddd.hh:mm:ss"
string reminderFormatted = $"{(DateTime.Now - reminderDate).Days:D3}.00:00:00";

Console.WriteLine("90-Day Reminder: " + reminderFormatted);


I hope it will solve your problem. let me know if you have any query.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900