Ok, say a user buys a 6 month subscription to my online app. Using c# or vb.net, How would I work out what the expiry date should be to be inserted into the database.
+4
A:
How about:
DateTime todaysDate = DateTime.Now;
DateTime expirationDate = todaysDate.AddMonths(6);
Jose Basilio
2009-06-10 14:32:17
+3
A:
You can use the DateTime.AddMonths
method to create a new DateTime
instance, adding 6 months to DateTime.Now
(or maybe add six months and one day to DateTime.Today
if you want the subscription to end at midnight or you're only keeping track of dates and not times in the database).
int subscriptionLengthInMonths = 6;
DateTime expiryDate = DateTime.Now.AddMonths(subscriptionLengthInMonths);
bdukes
2009-06-10 14:32:57