I know you can get the current date and time using the Now() function, but how would you get the date of yesterday?
You can use the Yesterday or IncDay(Now,-1) function from System.DateUtils as follow:
uses System.DateUtils;
begin
// Example 1:
ShowMessage('Yesterday = ' + DateToStr(Yesterday)); // Date of yesterday
ShowMessage('Today = ' + DateToStr(Date)); // Date of Today
ShowMessage('Tomorrow = ' + DateToStr(tomorrow)); // Date of tomorrow
// Example 2:
ShowMessage('Yesterday = ' + DateToStr(IncDay(Now,-1))); // Date of yesterday
ShowMessage('Today = ' + DateToStr(Now)); // Date of Today
ShowMessage('Tomorrow = ' + DateToStr(IncDay(Now,1))); // Date of tomorrow
end;
These functions return a TDateTime data type. The time component is set to zero.
Why not just use Date - 1 ?
Since one day is 1.0 in TDateTime encoding, substracting 1 is enough.
Related
How can decrement the current day or increment in Angular 7 using this property "Date.now()" that is in Documentation ?
Component
today: number = Date.now()
HTML
<td>{{ today | date: 'dd/MM/yyyy '}}</td>
let date= new Date();
let diff = 1; //1 to increment and -1 to decrement
date.setDate(today.getDate() + diff);
100 working solution
today=new Date();
constructor(
) {
console.log('11... today date',this.today);
var tom=this.today.setDate(this.today.getDate()+3);
var tomformatted=formatDate(tom, 'yyyy-MM-dd HH:MM:ss',
'en-US');
console.log('11... tommorow formatted date',tomformatted);
}
Console Logs
Is there a way in Groovy to get the duration between two Date objects? The duration format I'm looking for would be something like: 2 days, 10 hours, 30 minutes...
Thanks
TimeCategory has some methods for getting a duration. You could use it like
use(groovy.time.TimeCategory) {
def duration = date1 - date2
print "Days: ${duration.days}, Hours: ${duration.hours}, etc."
}
The use()-Syntax is weird to me.
so I prefer it like this:
def duration = groovy.time.TimeCategory.minus(
new Date(),
new Date(session.creationTime)
);
def values = [
"seconds: " + duration.seconds,
"min: " + duration.minutes,
"hours: " + duration.hours,
"days: " + duration.days,
"ago: " + duration.ago,
];
I have a google sheet populated by a google form input with 1 column that has a start date, the 2nd has the start time (the time is a text input from a drop down menu in a time format (but it is text) - 09:00 - 09:30 - 10:00 ..etc) I'm trying to join the date and time input to create a calendar event with the end date the same day as the start day and end time 30 minutes after. Any help would be appreciated!
I have searched and found that the text string for time can be converted by removing the ' sign infront of the text time input by using:-
var withoutQuote = e.values[1].substring(1);
My current script for createEvent:-
var options = { description: namedValues.Description[0],
location: namedValues.Location[0],
guests:"info#domain.com"};
var cEvent = CalendarApp.getCalendarsByName("TEST")[0].createEvent(
namedValues.Name[0],
new Date(namedValues.Starts),
new Date(namedValues.Ends),
options)
}
I would like to create new date based on input date (namedValues.Starts) + concatenate start time (namedValues.Stime) and new date based on (namedValues.Starts) + concatenate start time (namedValues.Stime) + 30 minutes
Any help would be appreciated!
Ok, I was able to get the concatenates namedValues part right herewith edit code:-
function createEvent_ (namedValues) {
var options = { description: namedValues.Description[0],
location: namedValues.Location[0],
guests:"johan#inprint.co.za"};
var cEvent = CalendarApp.getCalendarsByName("TEST")[0].createEvent(
namedValues.Name[0],
new Date(namedValues.Starts + " " + namedValues.Stime),
new Date(namedValues.Ends + " " + namedValues.Etime),
options)
}
What I need now is the second part - I would like to create a new end date/time - based on new Date(namedValues.Starts + " " + namedValues.Stime) + 30 minutes
I am trying to make a custom publish date, because the user wants to use that as the publishing date and for sorting. The date will also be displayed on the page.
Here is what I want:
The user can input a date
The date can be empty (meaning it will be published now)
It has to use that date for sorting
The date has to be set to UTC time, so it's equal for everyone in the world
I am desperate and I cannot figure out how to do this.
Here is what I have tried so far: I found a neat little plugin, which displays the user's current UTC time next to the input field, so the person knows their UTC time. I modified that to always enter the current date in the input field:
var timer = setInterval(function () {
var date = $(".custom-date").val();
if (date === "") {
$(".custom-date").focus();
$(".custom-date").click();
$(".custom-date").trigger("click");
//the date has now been set on the input field
} else if (date !== "") {
var newDate = new Date(date);
var stringDate = newDate.getFullYear() + "-" + ('0' + (newDate.getMonth() + 1)).slice(-2) + "-" + ('0' + (newDate.getDate() - 1)).slice(-2) + " " + ('0' + (newDate.getHours() - offset)).slice(-2) + ":" + ('0' + newDate.getMinutes()).slice(-2) + ":" + ('0' + newDate.getSeconds()).slice(-2);
$(".custom-date").val(stringDate);
angular.element(".custom-date").scope().$apply(function () {
angular.element(".custom-date").scope().datetimePickerValue = stringDate;
});
clearInterval(timer);
}
}, 1000);
Yes, this looks like a lot... and no, it does not work. I do the focus/click/trigger on the element, because that will automatically set the time to be the user's local time. I then turn that into UTC time (offset is the UTC time offset). Then I apply the date to the element's scope and the value gets updated both in $scope and in the view (I can actually see it).
However, when I hit save and publish, the date gets reset (it's empty in the database). It's only when I physically click on the input field and select a new date it will actually update it. I like this method, as I am in 100% control of it, so is it possible? It would seem like setting the new date on the scope doesn't trigger the actual "new date has been selected".
Alternatively I have my Razor code here:
//selection is all my elements/nodes
selection.OrderByDescending(x => x.GetProperty("publishDate") != null).ThenByDescending(x => x.GetPropertyValue("publishDate")).Where(x => x.GetPropertyValue<DateTime>("publishDate") < DateTime.UtcNow);
So apparently before the Angular event is triggered, I need to, at least, call these:
$(".custom-date").trigger("click");
$(".custom-date").change();
So I did that right after I set my new date and now it works.
I have a MVC Web Application Im trying to Ajax call an action method to retrieve some datetime from the database, the problem is the value comes as "/Date(386028000000)/"
its a DateOfBirth actually which I m using a java script function to calculate the age:
function (DOB) {
var birthday = +new Date(DOB);
return ~~((Date.now() - birthday) / (31557600000));
}
Anyway i can fix the Date Format and get only the date in a proper format or change the Java-Script method to accept the current format of the date value ?
I got it
var FixedDate = new Date();
FixedDate .setTime(DOB.replace("/Date(", "").replace(")/", ""));
return ~~((Date.now() - FixedDate) / (31557600000));
Click here to check the Demo
Sample Javascript/JQuery
var = MyDate_String_Value = "/Date(386028000000)/"
var value = new Date
(
parseInt(MyDate_String_Value.replace(/(^.*\()|([+-].*$)/g, ''))
);
var dat = value.getMonth() +
1 +
"/" +
value.getDate() +
"/" +
value.getFullYear();
Result - "3/27/1982"