I have a list of members on my website, and I have their membership start date and expiry date stored in my database as timestamps. Now I want to send them emails
one month before membership expiry date
one week before membership expiry date
one day before membership expiry date
How can I determine if there is one month/week/day is left in expiry based on stored expiry date?
The project is done in Laravel 4.2, and I am using Carbon.
Any ideas?
See Carbon for all the details.
$now = Carbon::now();
$week = Carbon::now()->addWeek();
$month=Carbon::now()->addMonth();
if expiry_date is the stored expiry date and Member is the model, using eloquent, this will give all the members expiring in one week.
$members=Member::where("expiry_date","<", $week)->get();
Related
I'm trying to make an investment website where I want to set an expiration date exactly after a year that the registration was made. Upon the registration, an initial deposit is required which is the one with the value "500" which is fixed on every registration. I want to use the created_at timestamp from my database table money_trade_deposits as the reference for the start date and calculate the expiration date based on that after a year and pass it on my laravel blade view. I'm new to laravel and I have no idea how to this.
This is my money_trade_deposits table and I wanna base the expiration date from the created_at date.
Or it it possible to add a new timestamp row which will automatically calculate the expiration date adter a year? Any help will be much appreciated. Thanks a lot!
Since the created_at is automatically casted as a Carbon instance in Laravel, you can calculate the expiration date one year after with the ->addYear() method.
Ex: $model->created_at->addYear()->toDateTimeString().
Reference: Carbon doc
You must use Carbon here to add a year from the day of the initial deposit.
Laravel automatically wraps up created_at to Carbon instance, and Carbon instance you can easily add year using addYear() function. See Documentation https://carbon.nesbot.com/docs.
I will suggest you to create a new column for expiration date and set it initially rather than adding a year to created_at each time to check expiration. Anyway, Carbon is very useful for this type of date processings.
I have a database for membership site where users has a column day .This is number of days left until users membership expire.
Right now I run cron job daily at 12 AM to decrement day column by 1.
Is this the better solution or any other ideas available ? using date of registration and current today date.
Much better approach is to store membership expiration date and just compare with the current date.
Just stored the registration date and expiry date based on no.of.months selected, it's also by database, created by master screen. Now i need if may i change the no.of months in master screen expiry date must the change the date based on the registration date and no.of.months when i change.
Eg: i created the basic plan - 3 months , at the registration i selected the reg. date 2.1.2013 and selected the basic plan, so that i database the expiry date is stored in 2.4.2013. if i change the month 3 into 4, i need to change the expiry date is 2.5.2013.
Please see this code i hope this will help :
$regdate = '2.1.2013';
$expiredate = date("d.m.Y", strtotime('+3 month', strtotime($regdate)));
echo $expiredate;
Then its print 02.04.2013
Just a quickie,
I have a date in my database where a subscription to a service starts...
In your experience, do you think it's better to record the expiration period as a time.. so then i can add the time onto the date_created to see if it has expired... Or shall I just workout the date it will end in php and put that into a datetime in the database?
So, TIME or DATETIME for subscription length.
Ask me if you want more details.
I would use the end date, this way you only need to make one calculation when you add the record to your database. Every other time you can just compare the current date to the expiration date.
I'd be tempted to save the start date, as if you're storing the expiration date only and you want to change the subscription length from say, one month to three months, you've got to try and work out the original start date and then add your new subscription length back on.
Current MySQL table schema: "Date" column with yyyy-mm-dd values
Assuming you are building a web app to rent out XBox's. Would you:
Create a a few checkboxes with "Every Monday," "Every Tuesday," "etc..." (Implication: If it's every Monday, how would you insert dates of only Monday's into the DB? Perhaps only insert the Monday's for the next three months initially and auto-increment and keep the tables light?"
Use a multi-datepicker for users to select multiple dates (Implication: User experience drops since the user will need to select more dates as time progresses?)
Other options?
How would add "hours" in addition to dates?
Store the data separately:
Start date - the start of the range
End date - the end of the range
Days of the week - the days of the week during the range (store this as a JSON array)
Hours per day - the hours per day (store this as a JSON object, with either start/end time per day of the week)
Try taking a look at Google Calendar add event page. They organize the times very smartly. It should give you some ideas for it.