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
Related
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.
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 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"
I have this code
FileStream fs = new FileStream("Scores.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Write("Name: " + name_box.Text + " Time " + label1.Text);
sw.Close();
which is simple the label1 is assgined to a Timer tick as in the folowing
private void timer1_Tick(object sender, EventArgs e)
{
// Format and display the TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
label1.Text = elapsedTime;
}
now when I open the Text File I found the following results
Name: Tony Time 00:00:06.67Text: Time [System.Windows.Forms.Timer], Interval: 100
which are perfect but what is ( Text: Time [System.Windows.Forms.Timer], Interval: 100)
I don't want that to appear in the txt
thanx in advance
You probably have the following line somewhere else in your code:
label1.Text = timer1.ToString();
You should write-click the word label1 in your code, then click Find All References to see what else you're doing with it.
By the way, instead of creating a stream, you should use File.WriteAllText, like this:
File.WriteAllText("Scores.txt", "Name: " + name_box.Text + " Time " + label1.Text);
You are using FileMode.OpenOrCreate in the constructor. This does not erase the previous contents of the file. I suspect that if you delete the file and then try running your program again, you won't see any of that extra stuff.
I suggest either using FileMode.Create or FileMode.Append. Use the first if you want to overwrite the results, the second if you want to... well, append.