How do I subtract dates? - datetime

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

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

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.

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.)

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.

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.

Related

Get any days that have availablility from Cronofy

Using the availability API is it possible to get the DAYS only between two query periods that a user has availability in their schedule based on the provided duration? It is unreasonable to receive and process 512 time slots to, for example, see if the user has availability in the month of May. Plus that might not even be enough data.
For example if a user has the following available:
May 1 9am
May 2 between 9 and 3pm
May 3 no time
May 4 ...
Could we get a result that says, the user has at least 1 hour (ie provided duration query) for these days? In this case it might return an array of dates like May 1/2/4/... or an array of time slots like May 1 9am, May 2 9am, May 4 10 am
Not right now. But it's a request we've had before and we plan to support it later this year.

Allow update in FireStore in specific hours of every day

I want to allow users to update their document only in specific hours say 19th hour in the evening to 5th hours in the next morning. I have found the way to compare between day but note the time. I need a way to compare the evening hours of the same day and the morning hours of the next day.
This will make sure the update is only done between 19 and 5 in UTC:
allow update: if request.time.hours() > 19 && request.time.hours() < 5
You will have to customize this depending on the time zone you want to address

Google Analytics: How to compare real-time vs yesterday?

In the REAL-TIME / Overview page, you can see how much people are currently browsing your site. Although, how do you know if this current value is good or bad? I would like to know how much people were browsing my site the same time the day before, so I would know if I have 5% more or less people.
Also, how would I know if the site is doing it better or worse than 1, 2 or 5 hours before? The REAL-TIME shows the last 30 minutes of per minute page-views, but how do I know if the site is going down or up compared to a few hours before? 30 minutes is not enough.
Is there any add-on to add, custom modification to make, or free/paid service to complement?
You want to use the standard ("core") reporting. The dimensions that will help you are (UI / API):
Hour / ga:hour: A two-digit hour of the day ranging from 00-23 in the timezone configured for the account. This value is also corrected for daylight savings time. If the timezone follows daylight savings time, there will be an apparent bump in the number of sessions during the changeover hour (e.g., between 1:00 and 2:00) for the day per year when that hour repeats. A corresponding hour with zero sessions will occur at the opposite changeover. (Google Analytics does not track user time more precisely than hours.)
Hour of day / ga:dateHour: Combined values of ga:date and ga:hour formated as YYYYMMDDHH
Date Hour and Minute / ga:dateHourMinute: Combined values of ga:date, ga:hour and ga:minute formated as YYYYMMDDHHMM
Hour Index / ga:nthHour: The index for each hour in the specified date range. The index for the first hour of the first day (i.e., start-date) in the date range is 0, for the next hour 1, and so on
With the UI you can add a secondary dimension to reports or build custom reports, with the API you can need to build your requests from scratch (try the explorer, official API doc).

Session Expiry VB.NET 1 Day

I am building an internal intranet system, that will call up sales orders and I need it to remember the last sales order number they were looking at, even though I could put this in a database and call up the info I was wondering if I could use a session cookie for a longer time than 20 minutes I want to set the expiry to expiry time to a day or a week or so;
Session("SalesOrder") = 105793 'STORE THIS FOR A DAY OR WEEK
I hope you can help.

Do I need to get client's actual timezone or can I assume they are all in the EST timezone? (US-only web application)

I have a question about dealing with date & time in my web application. The application will sell monthly subscriptions. It shows dates only when clients buy and cancel subscriptions. Clients can buy additional services in the middle of the month. Application calculates a pro-rata to charge the client until his anniversary date.
I will store dates/times in UTC. It is only for US clients.
I am considering the following options and I would love to get feedback from more experienced developers:
1 - always present dates in EST. I can include a small caption explaining that all subscriptions uses EST. This would be simple as I would not have to deal with clients' timezones. However I am not so sure if clients would be put off by this. Any thoughts?
2 - always present dates in EDT. This would probably not work very well as it would be harder to explain the reason for using it. However I believe it would be simpler to process than EST.
3 - ask for client's timezone information when he signs up for the service and use that information. I don't think this would add too much complication, however I would have to offer them an option to change timezones and I would have to decide what to do with existing subscriptions when there is a change in timezone. If I go with this option I would ask the client to pick the timezone from a drop-down list.
4 - ask for client's location (City and State) and calculate the timezone myself.
5 - try to guess client's timezone based on his IP or another method (ideas???).
Options 3, 4 and 5 would probably be the most user-friendly. Option 1 seems to be the most straightforward to implement.
Sorry for the long post. If you took the time to read it, would you mind taking a little more time and sharing your thoughts and experience?
Thank you.
UPDATE 1 - 9/3/2011 - 17:08 MST
Just found out that PayPal records transactions using PDT and shows them to the client using the client's local timezone they setup when they signed up with PayPal.
I am now inclined to:
1 - show current date using PDT (to align with PayPal) - I will probably change the code to show date & time PDT. Currently I am only showing the date. I believe it will be clearer to the client if I also show the time.
2 - I will not show the anniversary date. I will let PayPal handle that. I will simply state that it is a monthly billing.
3 - When clients add a new service I will calculate the pro-rata using PDT and I will give them a three day grace period to account for timezone differences (thanks to Robert Levy below for suggesting it) and PayPal processing (I don't want to charge them a pro-rata amount if they are only a couple of days from their regular monthly charges).
Any thoughts?
Update 2 - 9/3/2011 - 21:01 MST
Just a quick update. After further research I found out that PayPal does send me a transaction date back. I am not going to show any dates until the client pays at PayPal and I receive confirmation. I will show PayPal's transaction date in the client's receipt.
Sounds like a plan. What do you think?
Just add a grace period of 24 hours from UTC. Easy to code, no extra UI, and unlikely to upset any customers.

Resources