tags:

views:

706

answers:

8

Hi,

Let's say that guy register's to my site for 5$ for 30 days. So how do I make code that automaticly after 30 days delete's his account?

Thanks for answers and sorry for poor english Respectfully, Tom

+10  A: 

Use the date handling functions of your preferred programming language. Do not attempt to implement it yourself. It's harder than you think.

recursive
A: 

Most likely you would run a cron job every day or so and check and see if an account's last payment was 30 days ago, and then delete the user. However, manipulating the date is difficult to explain unless we know what language you are using. Since you specified DateTime I'm going to assume that you mean the .NET DateTime object and then you can just do DateTime.addMonths(-1); or DateTime.addDays(-30) respectively.

Malfist
hehe, I stumbled upon adding negative days as well for .NET. Very handy!
Dillie-O
Well there is no method for minusDays, only add.
Malfist
+2  A: 

If you can, convert the registration date and the current time to UNIX timestamps. Then subtract their registration time from the current time and check if the result is greater than the number of seconds in 30 days. (60 seconds * 60 minutes * 24 hours * 30 days = 2592000 seconds.)

yjerem
Beware of weird behavior with daylight savings time.
derobert
A: 

If you just have to count 30 days you can count them as 30 * 24 * 60 * 60 = 2592000 seconds and simply subtract the unix timestamps.

Anything more complex than this is a PITA to implement yourself and yuo should follow recursive's advice.

rjack
A: 

wxWidgets has good date handling functions, as well as many others.

Rocketmagnet
+3  A: 

I'd suggest simply noting the account's expiration date in its record, rather than having some sort of scheduled process to delete expired accounts.

For a .Net example: when you receive the $5 payment, set the account's expiration date to DateTime.Now.AddDays(30), and reject login on an account where expirationDate < DateTime.Now.

In Java, you'd need to pour the Date into a Calendar in order to add days, then pour it back into a Date when you're done.

However, what facilities are available to handle dates are determined by your environment.

Jeffrey Hantin
A: 

WOW! I didn't expected so many answers so fast. I found what I was searching. Thanks again.

Tom
heh, welcome to StackOverflow. =)
Erik Forbes
A: 

in sql, I'd like to list all funds whose anniversary is due this year in 2 months time. what is the syntax?

You should ask this as a separate question, since it's not an answer to this question. THe "Ask Question" button is in the top right of the page.
sth