i have below code i want to show date according to hours how to add 48 hours in my current date please help me in this i am new in angularjs.
"startjob_datetime" : ISODate("2017-03-13T14:21:12.231Z"),
var hours = 48 ;
var startdate = new Date(schedule_entry.startjob_datetime);
var enddate = new Date(schedule_entry.startjob_datetime).setHours(hours );
i want enddate = ISODate("2017-03-15T14:21:12.231Z"),
but its not working please check
and if normal working hours is 8 , than how to change date according to this, because 48 hours means two days, but if 8 hours normal duty time , it is almost 5 days
"startjob_datetime" : ISODate("2017-03-13T14:21:12.231Z"),
var hours = 48 * 60 * 60 * 1000 ; //Since 1hr = 60 mins, 1 min = 60 seconds, 1 second= 1000 milliseconds
var startdate = new Date(schedule_entry.startjob_datetime);
var enddate = new Date(schedule_entry.startjob_datetime).getTime() + hours ;
);
//This will give you endDate in milliseconds
//And replace 48 with whatever hours you want to add to the start date
Related
Using moment, I'm trying to create an if statement to see if their joinDate is within 14 days.
let joinDate = ${moment(member.joinedAt).format("YYYY, MMMM Do dddd, HH:mm:ss")}
That's my current code to format when the user joined.
Basically what I'm saying (if you're not following) is how would I check if joinDate is within the last 14 days?
You may wanna use momentjs diff function to get the days difference between the current date and the input .
A Snippet for your reference
const selectedDate = "2021-08-07";
const date_temp = moment().diff(selectedDate, "days", true);
console.log('Is within 14 days? ',date_temp >= 0 && date_temp <= 14);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
I have 2 dates: 1.start and 2.end
format is like this.
12/4/2017 console.log(startDate);
12/20/2017 console.log(endDate);
I am writing a validation to check if the end date is bigger than start date throw error,but it is not working.
this is what i have tried:
var startDate = new Date(this.formB['startDateVal']).toLocaleDateString();
var endDate=new Date(this.formB['dueDateVal']).toLocaleDateString();
this is my condition:
if(endDate<startDate){
this.bucketMsgClass='fielderror';
this.bucketSuccessMsg = 'End Date is must lower than Start Date.';
}
where am i doing wrong.?
I've always just subtracted one of the dates from the other. If the result is negative, then Date 1 is before Date 2.
var d1 = new Date("12/12/2017");
var d2 = new Date("12/13/2017");
console.log(d1 - d2) // -86400000 (exactly 1 day in milliseconds)
So
if (d1 - d2 < 0) {
// d1 is smaller
}
Going through this link that explains comparing dates in javascript would probably help you understand the problem and solve it.
Compare two dates with JavaScript
Hi I am using Salesforce Apex,
I have a date as String as below. I need to add days to it using Apex.
String dateTime = '2017-07-08T23:59:59Z';
If I add one day to it then it should be 2017-07-09T23:59:59Z as string. How will I do this?
Thanks!
Beware the DST issue! The "addDays" function is not DST-aware, so if you step over a DST transition during the addition of days (in a time zone that has DST) then the time will be messed up.
To resolve this one split the date/time into separate date and time parts first, add the days to the date part then re-combine at the end, like:
DateTime dt = ...;
Integer days = ...;
Date d = dt.date().addDays(days);
Time t = dt.time();
dt = DateTime.newInstance(d, t);
If you are working in the UK (London) time zone the following anonymous Apex illustrates the issue nicely:
DateTime dt = DateTime.newInstance(2017, 10, 28, 23, 59, 59);
System.debug('Adding days directly: ' + dt.addDays(2));
Date d = dt.date().addDays(2);
Time t = dt.time();
dt = DateTime.newInstance(d, t);
System.debug('Adding days in parts: ' + dt);
You need to convert the string to a DateTime and then add days. You can format it back after
String stringDateTime = '2017-07-08T23:59:59Z';
DateTime dt = DateTime.valueOfGmt(stringDateTime);
DateTime tomorrow = dt.addDays(1);
DateTime nextMonth = dt.addMonths(1);
DateTime anniversary = dt.addYears(1);
String formattedDateTime = dt.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');
My objective is to count Lead records based on simple date range query in local time
Integer TotalLeads = [ Select Count() From Lead where createddate >= fromdate CreatedDate <= todate];
Fairly basic. However, the issue I'm running into is I only want to count the leads for the "local" time not UTC; createddate is in UTC for lead records.
Sample dates:
From: 03/23/2017
To: 03/29/2017
For these sample dates and my local time is UTC - 7 (Los Angeles), so my query would be
Integer TotalLeads = [ Select Count() From Lead where createddate >= 2017-03-23T07:00:00z AND CreatedDate <= 2017-03-30T06:59:59z];
If these are my dates, how do I append the local time so from date is 2017-03-23T07:00:00z and to date is 2017-03-30T06:59:59z?
Using from date first, I was able to do the following but can't figure how to keep it in local time
// Date
date ds = date.valueof('2017-03-23');
string dm = string.valueOf( ds.month());
string dd = string.valueOf(ds.day());
string dy = string.valueOf(ds.year());
// DateTime Midnight (UTC)
String SDate = string.valueof(dm +'/' + dd + '/' + dy + ' 12:00 AM');
system.debug(SDate); // -> 3/23/2017 12:00 AM
// DateTime (Local Time)
datetime ds2 = datetime.parse(SDate );
system.debug(ds2); // -> 2017-03-23 07:00:00
system.debug(ds2.format('yyyy-MM-dd\'T\'hh:mm:ss'')); // -> 2017-03-23T12:00:00
As you can see, using ds2.format put its in the format I need but back to UTC (midnight), I need it to be 2017-03-23T07:00:00
Any suggestions?
Thanks!
Figured what I was doing wrong. The date calculation was fine, it had to do with how this was being passed to a batch job.
Currently I'm using Code On Time to develop my system.
I got a default current date and time, after the user selects a completed date from lookup, I want to calculate how many days and hours have been taken by the user.
Is there any way to do this?
Is this what you're after?
declare #dateTimeNow datetime = getutcdate()
, #dateTimeThen datetime = '2012-11-28 12:00:00'
select case when DATEPART(hour,(#dateTimeNow - #dateTimeThen)) >0 then day(#dateTimeNow - #dateTimeThen)-1 else day(#dateTimeNow - #dateTimeThen) end days
, DATEPART(hour,(#dateTimeNow - #dateTimeThen)) hours
or
select DATEDIFF(day,#datetimethen, #datetimenow) - case when (DATEDIFF(Hour,#datetimethen, #datetimenow)) % 24 = 0 then 0 else 1 end days
, DATEDIFF(hour,#datetimethen, #datetimenow) % 24 hours