wasnt sure how to best describe this. I make an API call and one of the elements I get back is like the following
0 => array:3 [▼
"customId" => "12345"
"customName" => "Month"
"customValue" => "June 16"
]
As you can see the customValue is June 16, meaning June 2016. Is there any way I can add 1 month onto this, so to make it July 16? I know I could simply replace Jun with July using something like str_replace, but I do not want to change the expression month on month. What I am really looking for is to have the system understand that this is Jun 16 and 1 month needs adding onto it.
Would this be possible?
Thanks
To change the value of $monthAndDay:
$monthAndDay = "June 16";
$monthAndDay = date("F j", strtotime($monthAndDay." + 1 month"));
echo $monthAndDay; //outputs July 16
Within an array:
$arr = [
"customId" => "12345"
"customName" => "Month"
"customValue" => "June 16"
];
$arr["customValue"] = date("F j", strtotime($arr["customValue"]." + 1 month"));
http://php.net/manual/en/function.jdmonthname.php
Look at this.
It could be a way to do it with this command!
Hope I could help,
Skayo
Related
I have a query to get the number of insertions grouped by months. I have beberlei Doctrine extensions already installed and working, but the array return have the month number as key. How will be used in a chart line, I want to show the month name instead of month number.
What is the best way to do this?
This the query:
//get and format the current year
$date = new \DateTime();
$year = $date->format('Y');
//create query
$qb = $this->_em->createQueryBuilder();
$qb->select(['MONTH(p.createdAt) as month', 'count(ccp) as insertions'])
->from(CareConnectPatient::class, 'ccp')
->join('ccp.person', 'p')
->where('YEAR(p.createdAt) = :year')->setParameter('year', $year);
$qb->groupBy('month');
return $qb->getQuery()->getScalarResult();
And I do that with that result:
`$countMonths = count($cCPatientGroupedByMonth);
for ($count = 0; $count<$countMonths; $count++){
$arrayKeyAsMonth[$cCPatientGroupedByMonth[$count]['month']] = $cCPatientGroupedByMonth[$count]['insertions'];
}`
What gives me something like this:
array:3 [
4 => "1",
8 => "2",
9 => "2"
]
I what to know the best way to make this appear as:
array:3 [
april => "1",
august => "2",
september => "2"
]
Sorry for bad english and thanks!
have you tried using MONTHNAME() function?
instead of:
$qb->select(['MONTH(p.createdAt) as month', 'count(ccp) as insertions'])
try:
$qb->select(['MONTHNAME(p.createdAt) as month', 'count(ccp) as insertions'])
I am inserting selected DOB into database in "yyyy-mm-dd" formate using jquery date-picker. But when I am selecting DOB before 1970 then it gives me wrong DOB. eg. we select "August 19, 1949" then it show "August 19, 2049" in future year that is wrong. We are showing DOB in front-end using below mentioned code :
echo $newDate = date("M dS, Y", strtotime($BirthDetails['date']));
So please help me !!!
I'm using cakephp 3.0
When I print $BirthDetails['date'], it gives me
Cake\I18n\FrozenDate Object
(
[time] => 2011-08-19T00:00:00+00:00
[timezone] => UTC
[fixedNowTime] =>
)
Try this, use createFromFormat
// pass your date format
$date = DateTime::createFromFormat('d M Y','17 Jan 1949');
echo $date->format('Y-m-d');
DEMO
After a long period of searching, I found out my answer. We just need to do some changes in config/app.php file under the 'App' => []
replace
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'),
to
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'pl_PL'),
this is proper working in my scenario
I know exact date of the beginning of the month but I need to know when first week of this month begins and this week can start outside of this month.
I can do something like - find weekday when "MONTH" starts and subtract number of days to the beginning of the "WEEK" :
$weekday = d('w', $monthStartTimeStamp);
$weekStart = $monthStartTimeStamp - strtotime('1 day', 0) * (7 - $weekday);
Question :
Is there some way to make this calculation more generic for time frames that I do not know in advance?
Possible use cases :
Given some "DATETIME" get datetime of the first "YEAR"
Given some "DATETIME" get datetime of the first "MONTH"
Given some "DATETIME" get datetime of the first "WEEK"
Given some "DATETIME" get datetime of the first "DAY"
Given some "DATETIME" get datetime of the first "HOUR"
Given some "DATETIME" get datetime of the first "MINUTE"
For date time 2016-01-10 10:30 results would be :
YEAR : 2016-01-01 00:00
MONTH : 2016-01-01 00:00
WEEK : 2016-01-04 00:00
DAY : 2016-01-10 00:00
HOUR : 2016-01-10 10:00
MINUTE : 2016-01-10 10:30
P. S. most of the questions here specify what exactly time frame is required, e.g. "How to get beginning of the year", they do not answer how to do this for ant time frame.
Here's an idea in pseudocode:
You already have the hardest case for the week
For the rest: Convert the date to a format like: YYYYMMDDHHmm, then depending on the $interval just change the right X characters to 0:
`
$int2char = array(
'YEAR' => 8,
'MONTH' => 6,
'DAY' => 4,
'HOUR' => 2,
'MINUTE' => 0
);
$interval = 'MONTH';
$str = date("YmdHi", $timestamp);
$zeros = $int2char[$interval];
$d = substring($str, 0, 12-$zeros) . substring("00000000", 0, $zeros);
$date = DateTime::createFromFormat('YmdHi', $d);
echo $date->format('Y-m-d H:i');
`
Im new to php and not sure how to operate with the string or date. I have custom month names, stored in array:
$months = ['1' => 'my Jan', '2'=>'my Feb', '3'=>'my Mar', '4'=>'my Apr', //etc.];
I'd like to show the date with these month names, currently I show:
date_format(new DateTime($route->start_date), 'd F Y')
which gives 01 January 2016
I need to get 01 my Jan 2016.
Thanks
hope this will help.
<?php
$months = ['1' => 'my Jan', '2'=>'my Feb', '3'=>'my Mar', '4'=>'my Apr'];
$date = new DateTime($route->start_date);
echo '<br>'.$date->format('d').' '.$months[$date->format('n')].' '.$date->format('Y');
?>
I'm trying to display data on a line graph using Google Charts. The data displays fine, however I would like to set a date range to be displayed.
The data is sent from the database in a JSON literal format:
{
"cols": [
{"label": "Week", "type": "date"},
{"label": "Speed", "type": "number"},
{"type":"string","p":{"role":"tooltip"}},
{"type":"string","p":{"role":"tooltip"}},
{"type":"string","p":{"role":"tooltip"}},
{"type":"string","p":{"role":"tooltip"}},
],
"rows": [
{"c":[{"v": "Date('.$date.')"},{"v": null},{"v": null},{"v": null},{"v": null},{"v": null}]},
{"c":[{"v": "Date('.$date.')"},{"v": null},{"v": null},{"v": null},{"v": null},{"v": null}]}
]
}
Data is either displayed by week or month (null for easy reading) for example this week:
2012, 02, 06
2012, 02, 07
2012, 02, 09
Data isn't set for everyday of the week, therefore in this example only the dates above are shown. What I would like to be shown is the start of the week (2012, 02, 06) to the end of the week (2012, 02, 12) similar to the third example here.
I managed to get the whole week showing by checking if the date exists in the database and if not append an extra row will null data, this however meant the line was not continuous and the dates where not in order.
Could anyone offer any advice on how to I could go about doing this?
Thanks!
Did you try leaving the missing dates be missing dates (i.e. let the database return 2 values instead of 7)?
The continuous axis should handle missing dates, you just need to set the axis range from start to end of the week.
UPDATE
for interactive line chart the axis ranges can be set like this (as inspired by this thread):
hAxis: {...
viewWindowMode: 'explicit',
viewWindow: {min: new Date(2007,1,1),
max: new Date(2010,1,1)}
...}
see http://jsfiddle.net/REgJu/
"I managed to get the whole week showing by checking if the date exists in the database and if not append an extra row will null data, this however meant the line was not continuous and the dates where not in order."
I think you are on the right track you just need to do it in a slightly different way. I have the function like the below to make data continuous.
$data = array(
1 => 50,
2 => 75,
4 => 65,
7 => 60,
);
$dayAgoStart = 1;
$daysAgoEnd = 14;
$continuousData = array();
for($daysAgo=$daysAgoStart ; $daysAgo<=$daysAgoEnd ; $daysAgo++){
if(array_key_exists($daysAgo, $data) == true){
$continuousData[$daysAgo] = $data[$daysAgo];
}
else{
$continuousData[$daysAgo] = 0;
}
}
continuousData will now hold:
$data = array(
1 => 50,
2 => 75,
3 => 0,
4 => 65,
5 => 0,
6 => 0,
7 => 60,
8 => 0,
9 => 0,
10 => 0,
11 => 0,
12 => 0,
13 => 0,
14 => 0,
);
in that order, and then the data can be used in the charts without any gaps.
Perhaps you can use a different chart type? Dygraphs looks like it might be helpful.
Otherwise you may have to write your own custom chart type.