-1

我怎样才能减去两个日期(LblExpirydate.Text - Label3.Text)

        LblExpirydate.Text = String.Format("{0:dd/MM/yyyy}", dataReader(0))
        Label3.Text = System.DateTime.Now.ToString(("dd/MM/yyyy"))

LblExpirydate.Text = 01/05/2013

Label3.Text = 01/04/2011

4

1 回答 1

1

您可以从另一个日期中减去一个日期以获得 TimeSpan。您不应该尝试对字符串进行日期计算:您的程序可能会在某处违反假定的日期格式。

Dim dateFormat As String = "dd/MM/yyyy"
Dim rightNow As DateTime = DateTime.Now

Dim expiryDate As DateTime = rdr.GetDateTime(0)

Dim daysToExpiry As Integer = (expiryDate - rightNow).Days

LblExpirydate.Text = expiryDate.ToString(dateFormat)
Label3.Text = expiryDate.ToString(dateFormat)
LabelExpires.Text = daysToExpiry.ToString & " days"
于 2013-03-30T17:07:20.660 回答