The user is able to enter the amount of rain collected each day, by entering the amount of rain collected, and date. They should be able to enter rain collected in the past as well (by giving another date if needed).
So, how can i check (by using the created_at row) if the user has already entered some data for the current date? And if they have, update the value given for the specific date. I already know how to update etc, I just need a way to validate the date given.
I was trying to figure something out by using Carbon, But my head is about to explode, I can't seem to wrap my mind around this issue.
'created_at','>=',Carbon::today())
I know that wont work. The created_at looks like this:
2014-07-16 20:42:38
So I would need a way to check the current date, and skip the time/clock? How would my approach be on this?
Create your condition in query like below, to match only date in yyyy-mm-dd, to check the current date.
->whereDate('created_at','=',Carbon::today()->format("Y-m-d") )
Carbon::now()->toDateTimeString();
See how you can work with dates
Related
I'm in the planning stages of creating a historical database. I will be using PHP, MYSQL and JavaScript for the website.
Often someone will know what year a person was born or picture was taken, but not the month or the day.
Is it possible for a PHP DATE variable and MYSQL DATE to be:
1920-00-00 or 1845-12-00 ?
If not, unless someone has a better idea, I'll have to create a column for year, another column for month, and yet another for day then do a bunch of value checking and combining.
Thoughts?
Thanks.
You need exakt dates for using date in mysql, so you probably have to bite down and filter everything for validating and then some code to combine it.
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.
I have never collected DOB before. This is the first time i am doing it.
What is the best way to first of all collect dob from the php form?
Do i allow them to enter it as 12/03/1979 or something like 12031979.
And do i need 3 fields in the db like month, day, and year?
And then for the db, what do i select for the type, date? I want to be able to reuse this data for research purposes later.
Thanks a bunch!
Do you mean Date of Birth?
You will use DATE as datatype.
For the GUI, I suggest using three dropdown boxes: Year, Month and Day. Use 4 digits for years and month names (rather than numbers) to make it crystal clear.
Under no circumstances let the user enter a date in a text field, because you won't be able to parse it correctly afterwards.
Is there any way to validate the time field based on the current time. I already posted a simillar question but now i decided to move away from that option and just want to try this.
1) ask an user to select time (I am using jquery timepicker).
2) See if that time is future time and not which is already gone.
I also have a datepicker, so if there is a way to check the time for that date then that would be great. For example, if one user select "august 10 2010(todays date)" from the date picker and then select time using timepicker, let say user select 6am , is there any way to see if that time for that date is already gone? because that user cannot choose a time which is already gone. I am fine if there is any php solution to take these two fields and see if it's a valid entry or not. Please guide me.
I just found that the date picker for the current and future date is working based on system date, I had my system date changed to aug 6th and the date picker started showing from Aug 6th. Any idea if this can be fixed?
You can use mktime() to solve all of those problems. It will create a unix timestamp if the date is correct (otherwise it will return false). And you can also check if the value is greater than the current timestamp (using the time() function).
This is a double question in terms of front end usability and PHP DATE_TIME validation.
I am working on a site for a client who would like to add the date he finished a project (so the projects can be listed in that order). He will be the only one using the admin interface, so I would like it to be as simple as possible.
I am storing the dates as DATE_TIME in a SQLite db.
I would like to require the client enter at least the year and month, with the option to add day, hour, minute, second to the DATE_TIME. If these are not set they will default to the smallest number.
I thought the best way and easiest to do this was making a single input form taking the input(left) and making the result(right). Making him use xxxx/xx/xx/xx/xx/xx as the format.
2009/08 = 2009-08-01 00:00:01
2009/08/01 = 2009-08-01 00:00:01
2009/08/01/05 = 2009-08-01 05:00:01
(adding one second as default otherwise it will be the day before)
I tried first by exploding the input into an array and validating each date section with regex. it got messy real fast and I can't figure out how to validate the proper ranges, say, /[1980-2009]/ or /[01-12]/ (that doesn't work like I expected). Also /[(0-9){2}]/ isn't going to work for the month obviously.
Another option is making each date section a separate select field. Making each field after month optional. But that gets messy in the html output, also given that each month doesn't have 31 days, I would need some javascript to change the day field depending on what month is selected. That's too much. It also seems a lot easier and faster to use a single field.
What do you guys suggest is the best way to input and validate custom datetimes?
I would reccomend calling strtotime() on the date, that way he can enter a variety of date formats, including month/year, day/month/year, day/month/year hours:minutes, and year-month-day hours:minutes
If strtotime can't determine what the date is, it returns false (or -1 in older versions of PHP, check your manual). SO your general code would be:
Run input through stripslashes (if needed) and strtotime
Check if value is === false. If so, display error
Otherwise, format the time as yor database expects is using date()