CakePHP grouping if row contains the same value - cakephp

<?php
$user_first = "123";
$query = $this->Post->find("all", array("conditions"=>array("userid"=>$user_first, "type"=>"message"), "group"=>"date"));
foreach($query as $val){
echo $val["message"];
echo $val["date"];
}
?>
<div>
//Using foreach the results would be like this:
Jan 10 2012 Hello
Jan 10 2012 Hi
Jan 10 2012 Hey
Jan 10 2012 Yo!
Jan 12 2012 Nice
But I would want to achieve is this:
Jan 10 2012
Hello
Hi
Hey
Yo!
Jan 12 2012
Nice
</div>
I want to group the results using date. So that the if the dates have the same result, they dont have to be redundant. Thanks.

Try like this.
$newDate =null;
foreach($query as $val) {
if ($newDate !== $val["date"]) {
echo $val["date"]. "<br />";
}
echo $val["message"];
$newDate = $val["date"];
}

Cast/Convert the values to a Date type for your group by.
GROUP BY CAST(myDateTime AS DATE)

Related

How can I compare a date formatted with dayjs() and compare the output with "a week"/"7 days" in react typescript

I am currently building a function that gets the local time with dayjs, compares it with a time stamp of a file and creates an output depending on the time difference.
For better understanding, here's my code:
function dateFormat(date: string){
const dateTemplate = dayjs(date).locale("de");
if (dateTemplate.from(dayjs()) <= '24:00') {
formattedDate = dateTemplate.format('HH:mm [h]'); //output: 00:00 h
} else if (dateTemplate.from(dayjs()) > '24:00'){
formattedDate = dateTemplate.from(dayjs()); //output: x days ago
} else if (dateTemplate.from(dayjs()) > '7 days ago'){
formattedDate = dateTemplate.format('DD MMM YYYY'); //output: 01 Jan 1970
}
return (
<>
<div>
{formattedDate}
</div>
</>
)
}
I want to add another condition in the first else if {} statement like this
&& dateFormatted.from(day(js)) <= '7 days ago') {
formattedDate = dateTemplate.from(dayjs());
}
My current output looks like this:
31 min ago
4 days ago
7 days ago
14:35 h (should be something like 22 Feb 2022)
Everything works, but the second else if is being ignored.

Define last week from [date]

I have issue extracting week/year from DATE column.
We are in week 02 of 2022 and my goal is to set MAX week to be "01 2022" at the moment.
Goal is to have dynamic calculated column or measure that will always show previous week.
weekMax = FORMAT(MAX(fact[date]),"WW YYYY")
With this solution it is showing me 03 2022 result.
Is there a way to sort this out?
You could try something like:
weekMax =
VAR lastweek = FORMAT(DATEADD('Table'[Date].[Date], -7, DAY) ,"WW YYYY")
RETURN
IF(FORMAT(TODAY() - 7 ,"WW YYYY") = lastweek, lastweek, BLANK())
Output:
Or if you always just want the last week without considering any columns, you can use:
weekMax = FORMAT(TODAY() - 7 ,"WW YYYY")

how to convert date object in 14 Dec 2020 from database in reactjs

When I tried to convert 2020-12-14 to 14 Dec 2020 by using
1st Method
<small>{item.date}</small>
2nd Method
{new Date(item.date).toLocaleString()}
then I got below output
2020-12-14
12/14/2020, 5:30:00 AM
Is there any way to convert the date format from 2020-12-14 to 14 Dec 2020.? in reactjs
A small modification to this elegant answer by Dave splits the toString date string into an array and formats it into the result you want. Check the code below:
const date = new Date(2020, 11, 14).toString().split(" ");
// ["Mon", "Dec", "14", "2020", "14:05:53", "GMT+0100", "(Central", "European", "Standard", "Time)"]
console.log(date[2] + " " + date[1] + " " + date[3]);
// 14 Dec 2020
using moment package
moment(moment('2020-11-18', 'YYYY-MM-DD')).format('DD MMM YYYY');

Suite CRM , Creating users Issues

MY issue that when am trying to create a normal user from Suite CRM ( User Management ) after pressing save , the server getting loading without any response and in the same time another active user getting msgs ( Cannot connect to data base ) until i need to restart the server ?
Wed Sep 11 11:33:41 2019 [30147][8dfa3f2c-e526-6242-6732-585643139abd][INFO] Query: SELECT alerts.* , jt0.user_name modified_by_name , jt0.created_by modified_by_name_owner , 'Users' modified_by_name_mod , jt1.user_name created_by_name , jt1.created_by created_by_name_owner , 'Users' created_by_name_mod , jt2.user_name assigned_user_name , jt2.created_by assigned_user_name_owner , 'Users' assigned_user_name_mod FROM alerts LEFT JOIN users jt0 ON alerts.modified_user_id=jt0.id AND jt0.deleted=0
AND jt0.deleted=0 LEFT JOIN users jt1 ON alerts.created_by=jt1.id AND jt1.deleted=0
AND jt1.deleted=0 LEFT JOIN users jt2 ON alerts.assigned_user_id=jt2.id AND jt2.deleted=0
AND jt2.deleted=0 where (alerts.assigned_user_id = '8dfa3f2c-e526-6242-6732-585643139abd' AND is_read != '1') AND alerts.deleted=0
Wed Sep 11 11:33:41 2019 [30147][8dfa3f2c-e526-6242-6732-585643139abd][INFO] Query Execution Time:0.0002281665802002
Wed Sep 11 11:33:41 2019 [30147][8dfa3f2c-e526-6242-6732-585643139abd][DEBUG] process_full_list_query: result is mysqli_result Object
(
[current_field] => 0
[field_count] => 23
[lengths] =>
[num_rows] => 0
[type] => 0
)
Wed Sep 11 11:33:41 2019 [30147][8dfa3f2c-e526-6242-6732-585643139abd][WARN] Saving error level. Try to remove the error_reporting() function from your code.
Wed Sep 11 11:33:41 2019 [30147][8dfa3f2c-e526-6242-6732-585643139abd][WARN] Pop error level. Try to remove the error_reporting() function from your code.
Wed Sep 11 11:33:41 2019 [30147][8dfa3f2c-e526-6242-6732-585643139abd][DEBUG] Hook called: ::server_round_trip
Wed Sep 11 11:33:41 2019 [30147][8dfa3f2c-e526-6242-6732-585643139abd][DEBUG] Calling MySQLi::disconnect()

Turn array of strings into array of dates in Google Apps Script

I have a Google Sheets spreadsheet. In Column B, I have a list of strings that are either dates or ranges of dates in the format month/date. For example:
7/26
7/27-7/31
8/1
8/2
8/3-8/5
I want to create an array with the first date on the left and the second date (if any) on the right. If there's no second date, it can be left blank. This is what I want:
[7/26,]
[7/27,7/31]
[8/1,]
[8/2,]
[8/3,8/5]
I've tried:
var r = 'B'
var dateString = sheet.getRange(dateColumns[r] + '1:' + dateColumns[r] + lastRow.toString()).getValues();
var dateArr = Utilities.parseCsv(dateString, '-');
But that just keeps concatenating all values. Also if it's possible to put the output in a date format that would be great too.
This was a funny exercise to play with...
Here is a code that does what you want :
function test(){
convertToDateArray('7/26,7/27-7/31,8/1,8/2,8/3-8/5');
}
function convertToDateArray(inputString){
if(typeof(inputString)=='string'){inputString=inputString.split(',')}; // if input is a string then split it into an array using comma as separator
var data = [];
var datesArray = [];
for(var n in inputString){
if(inputString[n].indexOf('-')==-1){inputString[n]+='-'};// if only 1 field add an empty one
data.push(inputString[n].split('-'));// make it an array
}
Logger.log(data);//check
for(var n in data){
var temp = [];
for(var c in data[n]){
Logger.log('data[n][c] = '+ data[n][c]);
var date = data[n][c]!=''? new Date(2014,Number(data[n][c].split('/')[0])-1,Number(data[n][c].split('/')[1]),0,0,0,0) : '';// create date objects with right values
Logger.log('date = '+date);//check
temp.push(date);
}
datesArray.push(temp);//store output data in an array of arrays, ready to setValues in a SS
}
Logger.log(datesArray);
var sh = SpreadsheetApp.getActive().getActiveSheet();
sh.getRange(1,1,datesArray.length,datesArray[0].length).setValues(datesArray);
}
Logger result for datesArray :
[[Sat Jul 26 00:00:00 GMT+02:00 2014, ], [Sun Jul 27 00:00:00 GMT+02:00 2014, Thu Jul 31 00:00:00 GMT+02:00 2014], [Fri Aug 01 00:00:00 GMT+02:00 2014, ], [Sat Aug 02 00:00:00 GMT+02:00 2014, ], [Sun Aug 03 00:00:00 GMT+02:00 2014, Tue Aug 05 00:00:00 GMT+02:00 2014]]

Resources