I am using this validation for dates:
'fiscal_end' => 'required|date_format:dd/mm/yyyy'
Doing:
print_r(Input::all());
die();
I get:
[fiscal_end] => 25/01/2017
I don't understand what's wrong here that generates the error: Date needs to be in proper format dd/mm/yyyy.
I am using Laravel 5.3 and datefield on form is actually Bootstrap Datepicker field.
You are doing with wrong format dd/mm/yyyy
Change your format as d/m/Y
Related
I am using Faker to generate a random Birthdate and feed the same in a Date input box in DD/MM/YYYY format through my automation script.
I tried this below snippet, however, it returns a date in YYYY/MM/DD format. I tried changing the from and to date format to DD/MM/YYYY as well, but no luck.
def self.get_birth_date
Faker::Date.between(from: '1950/01/01', to: '2001/12/31')
end
Would appreciate, if someone from the group can help. Thanks!
You could use strftime method:
Faker::Date.between(from: '1950/01/01', to: '2001/12/31').strftime("%d/%m/%Y")
It will return "29/05/1969"
My vue Js component is outputting a date in the format below. The component is actually making use of FlatPickr
2017-03-04T01:23:43.000Z
I have done quite abit of research and can see that the ISO time is in the format
2021-05-16T08:09:42+0000
I.e without the trailing 'Z' and also the seperator is a Z '.' and not a '+'
Will I need something like moment to convert the date into a suitable format to store in Laravel?
My column on my database is a DateTime column.
why dont you use carbon to input time directly from the database as you save the rest of the data.
'created_at' => \Carbon\Carbon::now(),
'updated_at' => \Carbon\Carbon::now(),
``
How do I validate that a given date is in the future and not a past date? Alternatively, does Html 5 allows one to disable past date from a date field?
I have a form in my app that allows user to select start date for an event from an HTML date input field. I want users to only choose a date in the future and not a past date.
I think you can use it like this:
$rules = [
'start_date' => 'date_format:d/m/Y|after:3/13/2019',
];
See also the laravel documentation:
https://laravel.com/docs/5.8/validation#rule-after
or
https://laravel.com/docs/5.8/validation#rule-after-or-equal
after:today works as #Tim Lewis commented above.
As for HTML validation, date fields still aren't fully supported. Safari being the main culprit.
You can use min="2020-01-01" format against the input, but you'll need to either add that date server-side or using JavaScript so it's tomorrow's date.
I have tried code and found that if you want to validate only year than you can write something like
$rules = ['dob'=>'required|date_format:Y|before:today']
where,
date_format
is fixed keyword and with help of 'Y' you can validate only year
and before:today validate if year is older than today or not.
you can use d-m-Y format instead only Y.
happy coding...
I have a persian datepicker in my view
<div class="input-group-addon" data-mddatetimepicker="true" data-targetselector="#exampleInput1" data-trigger="click" data-enabletimepicker="true">
<span class="glyphicon glyphicon-calendar"></span>
</div>
<input type="text" class="form-control" id="exampleInput1" name="start_at"/>
and i have a column in my table that in datetime format
when I send this to controller and dd($request['start_at']); it returns "۱۳۹۷/۰۷/۲۳ ۰۰:۰۰:۰۰"
How to convert this to datetime format to save in database?
Intro
Everything that is related to date or time in Laravel should be done with Carbon.
Carbon is a PHP Library/Extension to handle the formatting of Date and Time. You can find there docs over here. Carbonis already included in Laravel, so check the API out over here.
Getting things done
What you need to do is, pass in your timezone here:
$date = Carbon::now($start_at)->locale('UTC+6');
Assuming that the persia timezone is UTC+6the above snippet converts your time to a carbon time.
After this you can access your timestamp with
$date->timestamp;
Or your DateTimeString with
$date->toDateTimeString();
Please note: I am not absolutely sure about the time settings in persia. From a quick research I would assume that is UTC+6. You can also put in a string in the locale() function like:
$date = Carbon::now()->locale('fr_FR');
if this is easier to you!
Quickshot URLs:
Laravel Carbon API
Carbon API
use this package of laravel to convert date Persian to DateTime
laravel persian datetime package
I am using kendoui datepicker into inline grid,So i want to change default date format of min.js file . format like yyyy/mm/dd so please suggest me appropriate solution.
you can directly provide the format like
$('#datePicker').kendoDatepicker({
format: "yyyy/MM/dd"
});