How can I loop dates for a specified time? - php

I need to loop dates, according to different $eventname. I was already able to write a script that adds one week to the original date, but I don't know how I can loop it for a defined time.
code used:
$eventname = $event->title;
// TODO: loop for specified times if $eventname contains definded strings
$start_date = helper('com://site/ohanah.date.format', array(
'date' => $event->start,
'format' => 'Y/m/d H:i',
'timezone' => 'UTC'
));
$date = strtotime($start_date) + 604800;
echo "<pre>";
echo date('d. F Y, H:i', $date);
echo ' - ';
echo helper('com://site/ohanah.date.format', array(
'date' => $event->end,
'format' => 'H:i',
'timezone' => 'UTC'
));
echo "</pre>";
Output: (start date would be one week before) 18. April 2018, 14:00 - 16:00
So my question is, how can I loop this that the output is e.g. 6 times with one week space between each of them?

When working with dates and times, do not add seconds to timestamps or something like that, because it will get you in trouble in leapyears and daylight saving times, because one day is not always 86400 seconds.
Better use PHP's DateTime and DateInterval classes.
<?php
$Date = new DateTime("2018-03-03 14:00:00");
for($i=0;$i<6;$i++) { //loop 6 times
$Date->add(new DateInterval('P1W')); //add one week
echo $Date->format("Y-m-d H:i:s").PHP_EOL;
}
Output:
2018-03-10 14:00:00
2018-03-17 14:00:00
2018-03-24 14:00:00
2018-03-31 14:00:00
2018-04-07 14:00:00
See also:
http://php.net/manual/en/class.datetime.php
http://php.net/manual/en/class.dateinterval.php

Something like that?
<?php
$oneWeek = 604800;
$date = '2018-04-05';
$dates = array($date);
for ($i = 0; $i < 6; $i++) {
$dates[] = $date = date('Y-m-d', strtotime($date) + $oneWeek);
}
var_dump($dates);

I am not entirely sure I understand the question, but it looks like you want to have a condition that will either set a specific number of times for the output loop or determine whether the loop is ran that number of times.
If so, you can set a counter variable with your condition, then run the loop that number of times, defaulting the counter variable to 1 in the case that you do not want to output more than one time:
$eventname = $event->title;
// TODO: loop for specified times if $eventname contains definded strings
$counter = (/*your condition for $eventname*/) ? 6 : 1;
for ($x = 0; $x < $counter; $x++) {
$start_date = helper('com://site/ohanah.date.format', array(
'date' => $event->start,
'format' => 'Y/m/d H:i',
'timezone' => 'UTC'
));
$date = strtotime($start_date) + 604800;
echo "<pre>";
echo date('d. F Y, H:i', $date);
echo ' - ';
echo helper('com://site/ohanah.date.format', array(
'date' => $event->end,
'format' => 'H:i',
'timezone' => 'UTC'
));
echo "</pre>";
}

Related

If date string found to be between dates, return pay_period_start & pay_period_end. How?

The following code works if I manually type in every day for every single month in each hard coded array.
I then loop through the arrays for a match and if I find it, I return the first index and the last index value of that array. These are the pay period start and end dates later to be used with mysql select queries.
// MOUNTAIN DAYLIGHT SAVINGS TIME
date_default_timezone_set('MST7MDT');
// = PHP Default TimeZone
//print 'MOUNTAIN DAYLIGHT SAVINGS TIME';
//print '<p>';
// = MySQL CURRDATE() in MySQL DATETIME Format.
$php_current_date = date('Y-m-d');
// 2019 Pay Periods - MONTHLY
$parent_array = array(
1 => array('2019-01-01','2019-01-31'),
2 => array('2019-02-01','2019-02-28'),
3 => array('2019-03-01','2019-03-31'),
4 => array('2019-04-01','2019-04-30'),
5 => array('2019-05-01','2019-05-31'),
6 => array('2019-06-01','2019-06-30'),
7 => array('2019-07-01','2019-07-31'),
8 => array('2019-08-01','2019-08-31'),
9 => array('2019-09-01','2019-09-30'),
10 => array('2019-10-01','2019-10-31'),
11 => array('2019-11-01','2019-11-30'),
12 => array('2019-12-01','2019-12-31'),
13 => array('2020-01-01','2020-01-31'),
14 => array('2020-02-01','2020-02-29'),
15 => array('2020-03-01','2020-03-31'),
16 => array('2020-04-01','2020-04-30'),
17 => array('2020-05-01','2020-05-31'),
18 => array('2020-06-01','2020-06-30'),
19 => array('2020-07-01','2020-07-31'),
20 => array('2020-08-01','2020-08-31'),
21 => array('2020-09-01','2020-09-30'),
22 => array('2020-10-01','2020-10-31'),
23 => array('2020-11-01','2020-11-30'),
24 => array('2020-12-01','2020-12-31')
);
$current_pay_period_start = '';
$current_pay_period_end = '';
// For each child Array of date Strings inside parent Array of arrays...
foreach($parent_array as $child_array){
// Speculate the variable name as $result_found while searching each child Array of date Strings
// for the Current date in *Mountain Daylight Savings Time
$result_found = in_array($php_current_date, $child_array);
// if we have a match...
if ($result_found) {
// GET LEFT-MOST index and assign it to a variable.
$current_pay_period_start = current($child_array);
// GET RIGHT-MOST index and assign it to another variable.
$current_pay_period_end = end($child_array);
// Add a day for mysql query logic...
// because mysql uses < instead of =< for comparison in the query the follows...
$current_pay_period_end = date('Y-m-d', strtotime($current_pay_period_end . ' + 1 days'));
/*
Following Works ONLY on direct access.
Debug Only.
Eg. localhost/folder/filename.php
*/
print 'Php Current Date: ' . $php_current_date;
print '<br>';
print 'Current Pay Period Start: ' . $current_pay_period_start;
print '<br>';
print 'Current Pay Period End: ' . $current_pay_period_end;
exit;
}
}
I have tried to implement the solution below but, I keep getting errors related to me not being able to compare date strings... It seems I have learned to find date strings in an array of arrays but they aren't really dates as far as php is concerned.
/**
* #param DateTime $date Date that is to be checked if it falls between $startDate and $endDate
* #param DateTime $startDate Date should be after this date to return true
* #param DateTime $endDate Date should be before this date to return true
* return bool
*/
function isDateBetweenDates(DateTime $date, DateTime $startDate, DateTime $endDate) {
return $date > $startDate && $date < $endDate;
}
$fromUser = new DateTime("2012-03-01");
$startDate = new DateTime("2012-02-01 00:00:00");
$endDate = new DateTime("2012-04-30 23:59:59");
echo isDateBetweenDates($fromUser, $startDate, $endDate);
Here's how I try to call it and get the error...
isDateBetweenDates($php_current_date, $current_pay_period_start, $current_pay_period_end);
I have wrote the following for you, that compares the two dates from your array. Hopefully it will help!
$php_current_date = date('Y-m-d');
$parent_array = array(
1 => array('2019-01-01','2019-01-31'),
2 => array('2019-02-01','2019-02-28'),
3 => array('2019-03-01','2019-03-31'),
4 => array('2019-04-01','2019-04-30'),
5 => array('2019-05-01','2019-05-31'),
6 => array('2019-06-01','2019-06-30'),
7 => array('2019-07-01','2019-07-31'),
8 => array('2019-08-01','2019-08-31'),
9 => array('2019-09-01','2019-09-30'),
10 => array('2019-10-01','2019-10-31'),
11 => array('2019-11-01','2019-11-30'),
12 => array('2019-12-01','2019-12-31'),
13 => array('2020-01-01','2020-01-31'),
14 => array('2020-02-01','2020-02-29'),
15 => array('2020-03-01','2020-03-31'),
16 => array('2020-04-01','2020-04-30'),
17 => array('2020-05-01','2020-05-31'),
18 => array('2020-06-01','2020-06-30'),
19 => array('2020-07-01','2020-07-31'),
20 => array('2020-08-01','2020-08-31'),
21 => array('2020-09-01','2020-09-30'),
22 => array('2020-10-01','2020-10-31'),
23 => array('2020-11-01','2020-11-30'),
24 => array('2020-12-01','2020-12-31')
);
foreach ($parent_array as $child_array) {
//compare dates using strtotime, did the conversion in the if statement to retain the original date format, for output if results are found.
if (strtotime($php_current_date) >= strtotime($child_array[0]) && strtotime($php_current_date) <= strtotime($child_array[1])) {
// match found...
$current_pay_period_start = $child_array[0];
$current_pay_period_end = $child_array[1];
print 'Php Current Date: ' . $php_current_date;
print '<br>';
print 'Current Pay Period Start: ' . $current_pay_period_start;
print '<br>';
print 'Current Pay Period End: ' . $current_pay_period_end;
exit;
}
}
I have tested it and the following is outputted:
Php Current Date: 2019-03-07
Current Pay Period Start: 2019-03-01
Current Pay Period End: 2019-03-31
Hopefully this will help!

summed daylie sales of last 30 days output in google chart

I have a table with sales. From this table i take all results of the last 30 days, sum the prices with the same date and get this as array.
SQL:
SELECT date
, price
, id
, SUM(price) AS daylieprice
FROM sales
WHERE id = :id
AND date BETWEEN DATE_FORMAT(CURDATE() , '%Y-%m-%d') - interval 1 month AND DATE_FORMAT(CURDATE() , '%Y-%m-%d'))
GROUP
BY date
So i have for example:
ARRAY ['date'] - ARRAY ['daylieprice']
"2017-03-29" - "1"
"2017-04-02" - "5"
"2017-04-04" - "3"
Google chart is looking like that:
['<? echo date('d', strtotime("-2 day")) ?>', VALUE]
['<? echo date('d', strtotime("-1 day")) ?>', VALUE]
['<? echo date('d') ?> ', VALUE]
Is there a way to output the value of the array like that:
date('d', strtotime("-2 day") , ARRAY ['daylieprice']);
date('d', strtotime("-1 day") , ARRAY ['daylieprice']);
date('d', ARRAY ['daylieprice']);
Should mean to take the array value easy with date('d') or date('d', strtotime("-1 day") witouth making a loop for each value ?
Or does i have to make for every day a sql request?
I came up with this. I use DateTime to give more control and felxibility with input and output formats. This loops through your input array and subtracts 2 days from first entry, 1 day from 2nd entry and keeps 3rd entry the same:
<?php
$input = [
[
'date' => '2017-03-29',
'daylieprice' => 1,
],
[
'date' => '2017-04-02',
'daylieprice' => 5,
],
[
'date' => '2017-04-04',
'daylieprice' => 3,
],
];
$output = [];
$number_of_dates = count($input) - 1;
foreach ($input as $v) {
$date = DateTime::createFromFormat('Y-m-d', $v['date'])
->modify(sprintf('-%d days', $number_of_dates))
->format('Y-m-d');
$number_of_dates--;
$output[] = "'" . $date . "', " . $v['daylieprice'];
}
This produces an array like:
Array
(
[0] => '2017-03-27', 1
[1] => '2017-04-01', 5
[2] => '2017-04-04', 3
)
Hope this helps and you can figure out exactly how to implement it to solve your problem.
Edit: just saw echo date('d' so maybe you only want the day of the month, that's easy, you can just change ->format('Y-m-d'); in the loop to ->format('d');
Demo: https://eval.in/784353

Can not figure out why results do not match the date range that was specified with DateTime()

I already tried to find the answer by myself with the help of related posts like:
The first day of the current month in php using date_modify as DateTime object
PHP strtotime +1 month behaviour
PHP DateTime::modify adding and subtracting months
but unfortunately I wasn't able to find my mistake :-/ So I'm asking you for your support.
I'm currently trying to customize a wordpress theme for an event website and I'd like to enhance the existing search options with a filter by month.
I have a select box that contains all month from January - December:
<select id="listingFormTime" name="listingFormTime">
<option value=""<?php selected( $time, "" ); ?>><?php _e( "Any Time", "themesdojo" ); ?></option>
<option value="1"<?php selected( $time, 1 ); ?>><?php _e( "January", "themesdojo" ); ?></option>
<option value="2"<?php selected( $time, 2 ); ?>><?php _e( "February", "themesdojo" ); ?></option>
<option value="3"<?php selected( $time, 3 ); ?>><?php _e( "March", "themesdojo" ); ?></option>
...
<option value="12"<?php selected( $time, 12 ); ?>><?php _e( "December", "themesdojo" ); ?></option>
</select>
when selecting a month the corresponding records should be picked from the database and should be displayed. When selecting "March" all events that have their start date in March should be listed, etc.
The necessary event dates are stored in an additional table as "meta_key" and "meta_value"
event_start_date --> e.g.: 02/20/2016
event_start_time --> e.g.: 3:00 PM
event_start_date_number --> e.g.: 1455980400
event_end_date --> e.g.: 02/20/2016
event_end_time --> e.g.: 7:00 PM
event_end_date_number --> e.g.: 1455994800
I found out that I can use DateTime(); and have the option to modify and also use relative formats. So firstly I added the following 12 queries for each month:
if($time == 1) {
$dt_min = new DateTime('2015-12-31'); // January
$dt_max = clone($dt_min);
$dt_max->modify('+1 month');
$end_date = $dt_max->format('m/d/Y');
$date = $end_date." 23:59:59";
$event_start_date_number = strtotime($date); erzeugen
$time_args = array(
'key' => 'event_start_date_number',
'value' => $event_start_date_number,
'compare' => '<=',
'orderby' => 'value',
'order' => 'ASC',
);
} elseif($time == 2) {
$dt_min = new DateTime('2016-01-31'); // February
$dt_max = clone($dt_min);
$dt_max->modify('+1 month');
$end_date = $dt_max->format('m/d/Y');
$date = $end_date." 23:59:59";
$event_start_date_number = strtotime($date);
$time_args = array(
'key' => 'event_start_date_number',
'value' => $event_start_date_number,
'compare' => '<=',
'orderby' => 'value',
'order' => 'ASC',
);
...
} elseif($time == 12) { ...
Then I read that "modify('+1 month');" could lead to problems and found out that my results works perfectly for February but from March on the results aren't correct any longer.
So I tried to find another solution and tried to use another relative format: $dt_max->modify('last day of January 2016'); instead of $dt_max->modify('+1 month');
if($time == 1) {
$dt_min = new DateTime('2016-01-01');
$dt_max = clone($dt_min);
$dt_max->modify('last day of January 2016');
$end_date = $dt_max->format('m/d/Y');
$date = $end_date." 23:59:59";
$event_start_date_number = strtotime($date);
$time_args = array(
'key' => 'event_start_date_number',
'value' => $event_start_date_number,
'compare' => '<=',
'orderby' => 'value',
'order' => 'ASC',
);
} elseif($time == 2) {
$dt_min = new DateTime('2016-02-01');
$dt_max = clone($dt_min);
$dt_max->modify('last day of February 2016');
$end_date = $dt_max->format('m/d/Y');
$date = $end_date." 23:59:59";
$event_start_date_number = strtotime($date);
$time_args = array(
'key' => 'event_start_date_number',
'value' => $event_start_date_number,
'compare' => '<=',
'orderby' => 'value',
'order' => 'ASC',
);
Unfortunately same result here - February is fine but in March also the February events are shown. In April the events from February AND March are shown. It seems as if the next month's events are simply added and I do not know why ;-(
I thought when setting the new DateTime() each time to the beginning of the month the duration is limited?!
I am very sorry in case that this is a dumb question - I'm not a developer and have very poor programming skills but willing to learn. Your help and experiences are really appreciated.
After using:
var_dump($dt_min );
var_dump($dt_max );
var_dump($date );
var_dump($end_date );
var_dump($event_start_date_number );
I firstly get results as expected, so I can be sure that the variables are filled with information and datetime is working properly:
$dt_min --> object(DateTime)#5820 (3) { ["date"]=> string(26) "2016-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
$dt_max --> object(DateTime)#5819 (3) { ["date"]=> string(26) "2016-01-31 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
$date --> string(19) "01/31/2016 23:59:59"
$end_date --> string(10) "01/31/2016"
$event_start_date_number = int(1454284799) // 01. Februar 2016, 00:59:59 UTC+1
But there are two issues that are confusing:
$event_start_date_number = int(1454284799) // 01. Februar 2016, 00:59:59 UTC+1
the generated $event_start_date_number in UNIX Time should be 01/31/2016 23:59:59 in my understanding. But when decoding it there seem to be +1 hour to my timezone (GMT +1 Berlin) in January and from March it differs to +2 hours to my timezone (GMT +2 Berlin) - I guess this is due to Daylight Time, but I will have to consider this to make the correct events show up.
Is there a way to influence the timezone or can I subtract -1 or -2 hours from the Unix timestamp?
The second issue I figured out is:
(...)
$time_args = array(
'key' => 'event_start_date_number',
'value' => $event_start_date_number,
'compare' => '<=',
'orderby' => 'value',
'order' => 'ASC',
);
Could it be that I am only selecting events which start dates are smaller than the end date I defined? This would explain, why all events from the previous month are always listed -,-
I thought that I will limit the duration for the event selection with
$dt_min = new DateTime('2016-02-01');
$dt_max = clone($dt_min);
$dt_max->modify('last day of February 2016');
But in the array there seem to be no limitation from which starting point the events should be listed.
Is there a way to enhance the array in a way that only events are listed whose event_start_date_number is between $dt_min and dt_max?
Ok I figured it out by myself
Is there a way to influence the timezone or can I subtract -1 or -2 hours from the Unix timestamp?
I did it with a workaround and quick & dirty fix by editing the startdate and time in winter and summer to fix this +1 / +2 hour issue - even if I'm aware that there will be a few days the problem will still occur:
//WINTER (January, February, March, November, December)
$dt_min = new DateTime('2015-12-31'); // --> 01.01.2016
(...)
$start = $start_date." 23:00:01"; // --> 00:00:01 (+1 hour)
(...)
$end = $end_date." 22:59:59"; // --> 23:59:59 (+1 hour)
//SUMMER (April - October)
$dt_min = new DateTime('2015-03-31'); // --> 01.04.2016
(...)
$start = $start_date." 22:00:01"; // --> 00:00:01 (+2 hours)
(...)
$end = $end_date." 21:59:59"; // --> 23:59:59 (+2 hours)
For the second question I found a better solution with no workaround
Is there a way to enhance the array in a way that only events are listed whose event_start_date_number is between $dt_min and dt_max?
} elseif($time == 4) {
$dt_min = new DateTime('2016-03-31');
$dt_max = clone($dt_min);
$dt_max->modify('last day of April 2016');
// additionally defined a start date for the range based on $dt_min
$start_date = $dt_min->format('m/d/Y');
$start = $start_date." 22:00:01";
$start_date_number = strtotime($start);
$end_date = $dt_max->format('m/d/Y');
$end = $end_date." 21:59:59";
$event_start_date_number = strtotime($end);
// found out that I can have an array in an array ^^ to define the date range
$time_args = array(
'key' => 'event_start_date_number',
'value' => array ($start_date_number, $event_start_date_number),
'compare' => 'BETWEEN',
'orderby' => 'value',
'order' => 'ASC',
);
For now my problem is "solved" because the correct events are listed when selecting a month.

Timestamp with Custom Minute

I would like to make custom timestamps. I need to round the minute of the time to 00 or 30. I made already a PHP code for this:
if (date("i") >= '15' && date("i") < '45') {
$minute = "30";
}
else {
$minute = "00";
}
But, now, I want to make the timestamp with the time + date in it.
Does someone have a solution for this? I think I'll need to use strptime but I don't know how exactly..
You can use mktime to generate a timestamp rounded to the nearest 30 minutes:
echo date('Y-m-d H:i:s', mktime(date('H'), round(date('i') / 30) * 30, 0));
Example here:
http://codepad.org/3NCeWO21
The following code snippet:
<?php
date_default_timezone_set('America/New_York');
$format = '%d/%m/%Y %H:%M:%S';
$strf = strftime($format);
print_r(strptime($strf, $format));
?>
Produces this output:
Array
(
[tm_sec] => 49
[tm_min] => 48
[tm_hour] => 8
[tm_mday] => 14
[tm_mon] => 3
[tm_year] => 113
[tm_wday] => 0
[tm_yday] => 0
[unparsed] =>
)
I think you can take it from here.

Translating PHP date() for Multilingual Site

I'm trying to create a conditional translation of the PHP internal date() function. Is it possible to somehow redefine the internal variables - e.g. - date('M'), date('y') etc so that different strings are fed into the remainder of the PHP function on the basis of this test:
if (ICL_LANGUAGE_CODE == 'fr') { }
The following is a working example of the code I'm using for a dates module. Since $date is defined with many variables contained in this definition it's important to conditionally re-define the variables within PHP's date() first in order to avoid having to redefine the variable 100 times or more within each key.
if($start <= $end):
if($start == $end):
//Month Day, Year
$date = date('F', $start).' '.date('j',$start).', '.date('Y', $start);
else:
if($start_year == $end_year):
if($start_month == $end_month):
//Month Day - Day, Year
$date = date('F', $start).' '.date('j',$start).' - '.date('j', $end).', '.date('Y', $start);
else:
//Month Day - Month Day, Year
$date = date('F', $start).' '.date('j',$start).' - '.date('F', $end).' '.date('j', $end).', '.date('Y', $start);
endif;
else:
//Month Day, Year - Month Day, Year
$date = date('F', $start).' '.date('j',$start).', '.date('Y', $start).' - '.date('F', $end).' '.date('j', $end).', '.date('Y', $end);
endif;
endif;
endif;
Whenever you need to manipulate date/time stamps based on locale, you should use strftime:
switch ($lang) {
case 'en':
setlocale(LC_TIME, 'en_CA.UTF-8');
echo strftime("%B %e, %G");
break;
case 'fr':
setlocale(LC_TIME, 'fr_CA.UTF-8');
echo strftime("%e %B %G");
break;
}
Results:
February 11, 2011 // en
11 février 2011 // fr
Of course, you need to have the locales installed on your system. In Ubuntu per example:
bash-4.1$ sudo locale-gen fr_CA.UTF-8
EDIT in may 2022
strftime() has been DEPRECATED as of PHP 8.1.0
This is how you should do it:
$fmt = datefmt_create(
'pt_BR', // The output language.
\IntlDateFormatter::FULL,
\IntlDateFormatter::FULL,
pattern: "cccc, d 'de' LLLL 'de' YYYY" // The output formatting.
);
$input = strtotime('20-06-2022');
$output = datefmt_format($fmt, $input);
var_dump($output); // Outputs "segunda-feira, 20 de junho de 2022".
As for strtotime() use:
slash (/) for American M/D/Y formatting;
dash (-) for European D-M-Y formatting and
period (.) for ISO Y.M.D formatting.
In my sample I am using the european day-month-year formatting.
Click here to see how to format the value of $pattern parameter in datefmt_create().
You must have the intl package installed:
$ sudo apt install php8.1-intl
Change the 8.1 bit to the php version you are working with.
$date = date('F', $start).' '.date('j',$start).', '.date('Y', $start);
That's a rather painful way to go about. The format string in date() doesn't have to be a single character. This line could be reduced to
$date = date('F j Y');
And given that, you could have a simple
switch($whats_my_locale) {
case 'FR':
$format = 'date format characters for a french date';
break
case 'EN' :
$format = 'format chars for english date'
break
case etc....
default:
$format = 'default date format string here';
}
$local_date_string = date($format, $start);
and off you go.
I'm sure you have, but have you considered just using the numeric values?
Also, if you do use them, remember the US has months / day, opposite to the UK and others.
I was looking for this lately and I found out a way to translate datetime in php.
Let's take the fr example
First I created a new Class that extend GlobalDateTime
in App\Core\DateTime.php
namespace App\Core;
use DateTime as GlobalDateTime;
class DateTime extends GlobalDateTime
{
public function __construct($str_date = "now")
{
parent::__construct($str_date);
}
public function toLocalTimeString(): string
{
$Y = $this->format('Y');
$M = $this->_get('month', $this->format('m'));
$l = $this->_get('day', $this->format('l'));
$d = $this->format('d');
$H = $this->format('H');
$i = $this->format('i');
return "$l $d $M $Y à $H:$i";
}
private function _get($key, $id): string
{
return [
'day' => [
0 => "Dim",
1 => "Lun",
2 => "Mar",
3 => "Mer",
4 => "Jeu",
5 => "Ven",
6 => "Sam",
"Sun" => "Dim",
"Mon" => "Lun",
"Tue" => "Mar",
"Wed" => "Mer",
"Thu" => "Jeu",
"Fri" => "Ven",
"Sat" => "Sam",
"Sunday" => "Dimanche",
"Monday" => "Lundi",
"Tuesday" => "Mardi",
"Wednesday" => "Mercredi",
"Thursday" => "Jeudi",
"Friday" => "Vendredi",
"Saturday" => "Samedi",
],
'month' => [
"01" => "Jan",
"02" => "Fév",
"03" => "Mar",
"04" => "Avr",
"05" => "Mai",
"06" => "Juin",
"07" => "Juil",
"08" => "Aôut",
"09" => "Sept",
"10" => "Oct",
"11" => "Nov",
"12" => "Déc",
],
][$key][$id];
}
}
And then I can call it wherever I want like
use App\Core\DateTime;
$datetime = new DateTime('now');
$strdatetime = $datetime->toLocalTimeString(); // return vendredi 18 Aôut 2022 à 08:00
You can custom this DateTime class as you like
I hope this will help you.

Categories