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

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

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