Posts

Showing posts with the label date

How can I find closest date value from an array according to the current date?

How can I find closest date value from an array according to the current date? I want to get the next closest date on this array according to the current date. var dates = [ 'Aug 18, 2018 03:24:00', 'August 19, 2018 03:24:00', 'September 17, 2018 03:24:00', 'September 14, 2018 03:24:00', 'August 18, 2018 03:24:00', 'July 16, 2018 03:24:00', 'July 15, 2018 03:24:00', 'December 15, 2018 03:24:00', 'July 13, 2018 03:24:00', ]; var now = new Date(); 4 Answers 4 First you need to convert each date into a timestamp then subtract each of them by the current date and store the timestamp difference in the temp array then get the index of the minimum value and use the index to access the closest date in the original array. var dates = [ 'July 16, 1995 03:24:00', 'Aug 18, 1995 03:...

How to sort data coming from the API by date in Angular 4

How to sort data coming from the API by date in Angular 4 This is the JSON data i am fetching from POSTMAN. I want it to be ordered in a nearest to todays date. I tried many angular pipes but unfortunately nothings working. Any help would be great. I want to sort the date by the "broadcastOn" field. Thanks in advance. [ { "messageId": "09ca0609-bde7-4360-9d3f-04d6878f874c", "broadcastOn": "2018-02-08T11:06:05.000Z", "message": "{"title":"Server Side Test 2","text":"Different Message again","image":"https://api.adorable.io/avatars/285/abott@adorable.png","url":"https://www.google.co.in"}" }, { "messageId": "0a5b4d0c-051e-4955-bd33-4d40c65ce8f7", "broadcastOn": "2018-02-08T10:36:27.000Z", "message": "{"title":"Broadc...

Dates 20 years in the future considered invalid

Dates 20 years in the future considered invalid Laravel validator doesn't accept dates that are more than 20 years in the future: Route::get('test', function() { $input = ['date' => '2039-01-01']; $rule = ['date' => 'date']; $v = IlluminateSupportFacadesValidator::make($input, $rule); return 'Fails: '.$v->fails(); }); The following example returns true, despite the fact that the date is correct. But when I change 2039 to 2037, it works. How can I do to make the validator always return false? Check this: stackoverflow.com/questions/3953333/maximum-time-php – Mayank Pandeyz Jun 29 at 10:03 I see there will be a problem in 2038, but its there a way to bypass this limit for the validation as I'm using dates and not UNIX timestamps? ...

show difference in 2 times

Image
show difference in 2 times Its giving me like this instead of showing how many hours its showing "in hrs" but the real issue is even though the date is todays and time should show in minutes its giving me in hours.. I have to display time based on condition that if the order has been placed few minutes earlier it should show "1 min" , if few hours ago then "18 hr" if it is not of the present date it should show date in the format "29/06/18" . using moment.js any help is appreciated. "1 min" "18 hr" "29/06/18" moment.js This is my code: export class Notifications extends PureComponent { constructor(props) { super(props); this.state = { notificationsData: null, isLoading: true }; } componentDidMount() { if (notifications) { this.setState({ notificationsData: notifications.data, isLoading: false }); } else { ...