Wednesday 28 August 2019

PHP carbon library short cut && MYSQL date && laravel eloquent date && disable only full group by && javscript dates && PHP explode csv string

PHP carbon:

$now = Carbon::now(<date_string_or_empty>);
echo $now->year;
echo $now->month;
echo $now->weekOfYear;
Carbon::create($year, $month, $day, $hour, $minute, $second, $tz)."\n";
https://carbon.nesbot.com/docs/
https://stackoverflow.com/questions/40661011/carbonnow-only-month

MYSQL dates:

SELECT * FROM Table_name Where Month(date)='10' && YEAR(date)='2016';

https://stackoverflow.com/questions/7830987/how-do-i-extract-month-and-year-in-a-mysql-date-and-compare-them

Laravel Eloquent dates:

$post = Mjblog::whereYear('created_at', '=', $year)
              ->whereMonth('created_at', '=', $month)
              ->get();

https://stackoverflow.com/questions/32840698/how-to-select-year-and-month-from-the-created-at-attributes-of-database-table-in/32843415


JavaScript dates:
var unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');

// Javascript get month starts at 0
d1.getMonth() + 1 // month #
d1.getFullYear()

https://stackoverflow.com/questions/18624326/getmonth-in-javascript-gives-last-month
https://stackoverflow.com/questions/98124/why-does-javascript-getyear-return-108
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

MySQL disable full group by:

https://stackoverflow.com/questions/23921117/disable-only-full-group-by


CSV can be formed with a string separated by line break PHP_EOL :

              $out = "";
foreach($array as $arr) {
    $out .= implode(",", $arr) . PHP_EOL;

}

https://stackoverflow.com/questions/16352591/convert-php-array-to-csv-string









No comments:

Post a Comment