I got the fallowing date time field:
DateTime
::make('foobar')
->format('DD-MM-YYYY HH:mm:ss') // https://momentjs.com/docs/#/parsing/string-format/
->pickerFormat('d-m-Y H:i:S') // https://flatpickr.js.org/formatting/
->rules('required', 'date_format:Y-m-d H:i:s')
->firstDayOfWeek(1)
Momentjs does not recognise the date. I get a warning after changing the date in console:
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
It seems like momentjs is not getting the format? But I am clearly setting it in the nova resource and so it should get passed to vue, and so on? right?
Removing ->pickerFormat() allows me to save the date, but without displaying it the way I want in the picker.
I might be doing it completely wrong, so if someone could produce a working example of a DateTime filed with format and pickerFormat then that would be great as well.
edit:
Some more info. I re-transpiled Nova's using dev mode so I could poke around using Vue (chrome extension) tool.
I have also looked at the DateTime (vue) component without success. To bad it is closed source.
Use the package lathanhvien/novaofdatetime I just wrote recently. Hope it’s good to you!
Package link: https://packagist.org/packages/lathanhvien/novaofdatetime
I have problem in searching, I am using Laravel 5.5 version, the situation like this: I have groups which study during some period of time. On filtering page, Admin enters study starting date and ending date, the result must show all groups which studied or studying between given time period. A comparing in simple way is not working, I would like to use strtotime function, but when I use:
->where(strtotime('edu_ending_date'),'=<',strtotime($edu_ending_date));
the eloquent is saying there is not such a column name ...
if(!empty($input['daterange']))
{
$q->where(function($query)use($edu_starting_date,$edu_ending_date){
$query->where('edu_starting_date', '>=', "$edu_starting_date")
->where('edu_ending_date','=<',"$edu_ending_date");
});
}
if you need to use dates in your where clauses I might want to have a look at this article and this section of laravel docs where they mention additional where clauses which include also whereDate, whereDay, etc. Might come in handy. In your case I would suggest you to do two whereDate conditions to act as between:
$query->whereDate('edu_starting_date', '>=', $edu_starting_date)
->whereDate('edu_ending_date', '=<', $edu_ending_date)
Note that $edu_starting_date and $edu_ending_date are recommended to be a Carbon object or output of PHP's date function. If you want to use strings according to the Laravel docs it should be possible. Hopefully this helps you :)
You can use
$q->whereBetween('edu_starting_date', [$edu_starting_date,$edu_ending_date])
try this:
if(!empty($input['daterange']))
{
$q->where(function($query)use($edu_starting_date,$edu_ending_date){
$query->where('edu_starting_date', '>=', $edu_starting_date)
->where('edu_ending_date','=<',$edu_ending_date);
});
}
The date is saved as a string in my database, is that ok, that is why I would like to use
something like this:
->where(strtotime('edu_ending_date'),'=<',strtotime($edu_ending_date));
You can use DB::raw
->where(DB::raw("strtotime('edu_ending_date')"),'=<',strtotime($edu_ending_date));
Thank you guys, I found my stupid mistake, I stored date as a string.
I'm trying to make cron job for my system.
The project is configured for time zone that differs from mine
I tried
$timezone = date_default_timezone_get();
$current = Carbon::now(new \DateTimeZone($timezone));
It returns 2018-01-05 06:36:15
which had a wrong month
I tried $current_m = date('y-m-d h:m'); which returned
18-02-06 06:02
which had right date but wrong time
what should I do? I need to be using carbon $ I'm using laravel 5.4
The problem wasn't in Carbon, It was in using $current->subHours(48) several times.
I'm using laravel and I have problem with the server time configuration.
That means that the no matter what timezone I set laravel configuration to, The server time will always be 1 hour and 12 minutes ahead of the current timezone.
My question is - there any temporary/quickfix I can make in order to get the right hour and minute without relaying on the server timezones which are incorrect?
I know this is not problem of Laravel, but I need some quick fix ideas until I'll set up a new server or fix this issue. Any way to decrease 1 hour and 12 minutes to the laravel timezone?
If you have the difference of 1, 2 or 3 hours, you can change your timezone to get it right but with 1h12 there's no way to have a configuration of laravel to do that.
So, we'll use php to do that for you. Create a helper file helpers.phpunder app/. In this file, create the following function:
function getCurrentTime()
{
return date('Y-m-d H:i:s', time() - 4320);
}
Then, you must config your composer.json to autoload your helpers.php:
"autoload": {
...
"files": [
"app/helpers.php"
]
...
}
and you must run composer dump-autoload to make it work.
From now, you can call getCurrentTime() at any moment, it'll give you the time you desire.
Do you know of any way to check the current time in Joomla considering the selected time zone in global configuration?
I have been looking in administrator settings but did not see any single word about the current time.
You can use the following code:
$date = new DateTime();
$config = JFactory::getConfig();
$date->setTimezone(new DateTimeZone($config->get('offset')));
This does two things. The first line creates a DateTimeobject based on the current server time and timezone. The following two lines get Joomla's global configuration and change the timezone of out date object to that timezone.
You can then format the date to whatever format you like by calling $date->format('Y-m-d H:i:s');. You can replace the format specifier by whatever you need, a reference of possible formatting options can be found here: http://www.php.net/manual/de/function.date.php