Reputation:
Here are the parts of My Program.
Table:SGinfo
-Birthdate
-Age
VB.net form
Label6.text Respectively "Update Age of all Guards in the list"
My question in my Database there is a record in the table that contains this ---> "7/25/2013" How can i update a persons age by comparing only the Month and Day of the record in the databse in the Systems Month and Date also
Example
"7/15" Compare to database record like this "7/25/2013"
I dont know how to code this.
So please give a simple code about it TY.
Upvotes: 0
Views: 188
Reputation: 5038
if they are of same year then try, or change the date1.Year
as you likr
Dim date1, date2 As Date
Dim lDate1 As String
date1 = Date.Parse("7/25/2013")
lDate1 = "7/15" + "/" + date1.Year
date2 = DateTime.ParseExact(lDate1 , "dd/MM/yyyy", Null)
if (DateTime.Compare(date1, date2) > 0)
// which means ("date1 > date2")
if (DateTime.Compare(date1, date2) == 0)
//which means ("date1 == date2");
if (DateTime.Compare(date1, date2) < 0)
//which means ("date1 < date2")
or
Dim tSpan As TimeSpan
tSpan = date2 - date1
Upvotes: 0
Reputation: 35380
In the light of your explanation in the comment, you should read the value from the database and then split in on slash '/' character to get the chunks for date and month parts. Then afterwards, you can use int.Parse()
to convert these chunks into numeric values and compare them against DateTime.Now.Month
and DateTime.Now.Day
parts.
An alternate is to use something like DateTime.Now.ToString("MM/dd")
and compare it directly to the DB value you read.
Upvotes: 1
Reputation: 5719
You could make your Date from Database as a variable ..
Dim dBirth as DateTime = MyTable.Item("BirthDate") '---> get from table
If dBirth.Month = Now().Month AND dBirth.Day = Now().Day Then
'some code ...
End If
Upvotes: 0