date
php weeks between 2 dates
Here’s an alternative solution using DateTime:- function datediffInWeeks($date1, $date2) { if($date1 > $date2) return datediffInWeeks($date2, $date1); $first = DateTime::createFromFormat(‘m/d/Y’, $date1); $second = DateTime::createFromFormat(‘m/d/Y’, $date2); return floor($first->diff($second)->days/7); } var_dump(datediffInWeeks(‘1/2/2013’, ‘6/4/2013’));// 21 See it working
How to sort an array of objects by date?
As has been pointed out in the comments, the definition of recent isn’t correct javascript. But assuming the dates are strings: var recent = [ {id: 123,age :12,start: “10/17/13 13:07”}, {id: 13,age :62,start: “07/30/13 16:30”} ]; then sort like this: recent.sort(function(a,b) { return new Date(a.start).getTime() – new Date(b.start).getTime() }); More details on sort function from … Read more
Laravel: how to set date format on model attribute casting?
After laravel 5.6, You can individually customize the format of Eloquent date and datetime casting: protected $casts = [ ‘birthday’ => ‘date:Y-m-d’, ‘joined_at’ => ‘datetime:Y-m-d H:00’, ]; This format is used when the model is serialized to an array or JSON data
Working with INTERVAL and CURDATE in MySQL
You need DATE_ADD/DATE_SUB: AND v.date > (DATE_SUB(CURDATE(), INTERVAL 2 MONTH)) AND v.date < (DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) should work.
Parse time of format hh:mm:ss [closed]
As per Basil Bourque’s comment, this is the updated answer for this question, taking into account the new API of Java 8: String myDateString = “13:24:40”; LocalTime localTime = LocalTime.parse(myDateString, DateTimeFormatter.ofPattern(“HH:mm:ss”)); int hour = localTime.get(ChronoField.CLOCK_HOUR_OF_DAY); int minute = localTime.get(ChronoField.MINUTE_OF_HOUR); int second = localTime.get(ChronoField.SECOND_OF_MINUTE); //prints “hour: 13, minute: 24, second: 40”: System.out.println(String.format(“hour: %d, minute: %d, second: … Read more
How to save and retrieve Date in SharedPreferences
To save and load accurate date, you could use the long (number) representation of a Date object. Example: //getting the current time in milliseconds, and creating a Date object from it: Date date = new Date(System.currentTimeMillis()); //or simply new Date(); //converting it back to a milliseconds representation: long millis = date.getTime(); You can use this … Read more
How do I extract Month and Year in a MySQL date and compare them?
in Mysql Doku: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_extract SELECT EXTRACT( YEAR_MONTH FROM `date` ) FROM `Table` WHERE Condition = ‘Condition’;
Get Application Installed Date on Android
or this one (API Level 9 upwards!): long installed = context .getPackageManager() .getPackageInfo(context.getPackageName(), 0) .firstInstallTime ;
moment.js isValid function not working properly
In your question you write that moment(’03:55jojojo’, ‘HH:mm’,true).isValid(); returns true. This is incorrect. Please check your jsfiddle again. From http://momentjs.com/docs/ Moment’s parser is very forgiving, and this can lead to undesired behavior. As of version 2.3.0, you may specify a boolean for the last argument to make Moment use strict parsing. Strict parsing requires that … Read more