首页 > 解决方案 > 如何在 Web 表单应用程序中获取最后日期输出?

问题描述

我的任务是制作一个 Web 表单应用程序,用户输入一个日期,应用程序返回该月的最后一个日期作为输出。请帮助我构建它。我必须使用 EOMONTH 吗?

DECLARE @date DATETIME = '12/1/2011';  
SELECT EOMONTH ( @date ) AS Result;  
GO  

我是一个绝对的初学者。如果你告诉我一步一步的过程,这对我来说意义重大。

标签: c#asp.netsql-serverwebforms

解决方案


参考DateTime 类DateTime.TryParseDateTime.ToStringTextBox 类标签类

DateTime tempDate;
if (DateTime.TryParse(userInputTextBox.Text, out tempDate))
{
    DateTime newDate = new DateTime(tempDate.Year, tempDate.Month, DateTime.DaysInMonth(tempDate.Year, tempDate.Month));
    endOfMonthLabel.text = newDate.ToString("mm/dd/yyyy");
}
else
{
    endOfMonthLabel.text = "invalid date format";
}

推荐阅读