I am creating a google sheet that feeds from a form. I want to capture the timestamp in a separate cell when another cell is changed. I can get it to display the time now but I need it to be in military time.
var timezone = "GMT-4"
var timestamp_format = "hh:mm:ss"; // Timestamp Format.
I expect the output to say 13:15:55, but the actual is 1:15:55.
Google's App Script uses the standard JavaScript Date object when returning forms. Here is how to get what you want from a Date object.
var resultFromForm = ...
var time = resultFromForm.toTimeString().substring(0, 8);
you can just change internal formatting like:
Related
I am maintaining a tracker of sorts for enterprise wide. Recently my manager came to me with a request that he wants to see daily change against each of the respective business unit. The challenge is information is updated in real time and I don't have a time stamp to calculate the instance to be taken for calculation. Is there any way in Google Sheets to do that ?
Pasting the image below for better understanding
enter image description here
Make a short script that copy as values 'Cases (Live)' to 'Previous day Instance' column. And then put a trigger on that function to be activated each day at 23:59. Put a link to your project to go further. Example :
function histo(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('my Sheet');
var range = sheet.getRange('B5:B9');
range.copyTo(sheet.getRange('D5'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
to define a trigger based on time
function createTimeDrivenTriggers() {
// Trigger every day at 06:00AM CT.
ScriptApp.newTrigger('histo')
.timeBased()
.everyDays(1)
.atHour(6)
.create();
}
Reference:
Installable Triggers
New to MatBlazor below
<MatDatePicker #bind-Value="#Date1"></MatDatePicker>
Want to learn how to get date, format the date and get the time
Does this one has time component?
Thanks
Just get the value from variable Date1 from your component.
Example :
<MatDatePicker #bind-Value="#Date1"></MatDatePicker>
#code{
var formattedValue = Date1.ToString("dd mm yyyy");
var dateValue = Date1.Date;
var timeValue = Date1.TimeOfDay;
}
As the current version, the control have implemented ToLocalTime() default.
Please ask 1 question at a time.
MatDatePicker is based upon mat-datepicker
Best would to look into material design and the ui components for answers to your question
Even though it is for Angular, it gets close, for example look at Angular 6 material: how to get date and time from matDatepicker?
I am trying to query the adwords api (v201603) and am using/extending the Java examples provided.
The problem I am encountering is being able to specify a specific date to download the report data for the CLICK_PERFORMANCE_REPORT report. This report is restricted to returning a single days worth of data at a time (for up to the last 90 days).
I can get todays and yesterdays data using the specifiers : ReportDefinitionDateRangeType.TODAY and ReportDefinitionDateRangeType.YESTERDAY, but what I really need to do is be able to specify a specific date within the last 90 days in order to get as much historical data as possible.
I have tried the following:
DateRange dr = new DateRange();
dr.setMin("20160401");
dr.setMax("20160402");
selector.setDateRange(dr);
reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.CUSTOM_DATE);
reportDefinition.setReportType(ReportDefinitionReportType.CLICK_PERFORMANCE_REPORT);
reportDefinition.setDownloadFormat(DownloadFormat.CSV);
Both with and without the custom date specifier - and either gives the following error:
Report was not downloaded due to: HTTP Response Code: 400, Trigger: A single day DateRange is required for reportType: CLICK_PERFORMANCE_REPORT, Type: ReportDefinitionError.INVALID_DATE_RANGE_FOR_REPORT
Any help much appreciated, thanks in advance
You're going to have to use DURING and the same date string.
... + 'DURING 20161004,20161004';
Single Day Iterator for AdWords Scripts CLICK_PERFORMANCE_REPORT:
var start = new Date("12/01/2016");
var end = new Date("12/18/2016");
while(start < end){
var newDate = start.setDate(start.getDate() + 1);
start = new Date(newDate);
singleDay = start.toISOString().substring(0, 10).replace(/-/g,"");
console.log(singleDay);
}
Utilities.formatDate(start, timeZone, "yyyyMMdd"); formats date object as an 8-digit integer, so:
singleDay = Utilities.formatDate(start, timeZone, "yyyyMMdd");
Use singleDay in 'DURING ' + singleDay + ',' + singleDay);
Working with Dates and Times #Reporting — AdWords Scripts
Not really a language specific question, but my language in use in the examples below is Swift. The code itself is written to be somewhat language agnostic.
public class Employment {
public var payFrequency: PayFrequency
public var payPeriods: [PayPeriod]
// Other class data, variables, etc.
// Constructors, other functions, etc.
public func calculatePayPeriods(payBegin: NSDate) {
self.payPeriods = [] // Null out array
// Enter loop to the extent of calculation.. Infinity?
// Create the PayPeriod object with start, end, and # of hours worked.
// Advance # of days based on payFrequency
}
}
Now I have only included the respective variable(s) and function(s). My question in particular is obviously on the calculatePayPeriods(...) function. This function in particular will be called once the user inputs a single pay period start date. Since I obviously, or well practically, cannot generate the pay periods until the end of time and would prefer not to do year-by-year. My question is as follows: what sort of implementation would best suit a situation where the data being calculated can potentially span infinitely?
Here is the implementation, and a helper function if needed for reference:
public struct PayPeriod {
public var startDate: NSDate
public var endDate: NSDate
public var hours: Double
}
// Returns .Other(amount); 'amount' being in days.
// If 'amount' is compatible with any other case in the enum, then instead that
// case is returned.
public func determinePayFrequency(start: NSDate, end: NSDate) -> PayFrequency {
let converter: Double = 60*60*24 // 60 seconds 60 minutes 24 hours
let calendar = NSCalendar.currentCalendar()
let unit = NSCalendarUnit.CalendarUnitDay
let componentFlags = NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay
// Strip away any extra components we don't need such as hour/min/sec/etc.
var startDay = calendar.dateFromComponents(calendar.components(componentFlags, fromDate:start))!
var endDay = calendar.dateFromComponents(calendar.components(componentFlags, fromDate:end))!
// '+ 1' is to go THROUGH the end day.
return PayFrequency(days: Int(endDay.timeIntervalSinceDate(startDay) / converter) + 1)
}
I appreciate the time you took to read over my question and code. Thank you.
Best regards,
Steven
From what I understand, you want to basically give the user a reasonable range of dates initially and then populate dynamically if they request more. This is a really common practice.
For example, facebook's public home page does not have all the posts that they need in 1 huge page. Instead, they delegate only x amount of posts on the screen at once. Once the user scrolled to the bottom, there would be more loaded.
From what I understand, the background behind this is that facebook has a database that it's constantly retrieving json/xml data from to populate your public home page. Requests that are too big(in your case, infinitely big) would have to be truncated down to x amount, then facebook's cookies hold a variable as to where to retrieve data from in the database again.
The same can be applied with your algorithm. If you feel that the retrievals are VERY frequent, then you should keep a dynamic array(that can reallocate size, commonly by 2x the previous size if needed) and add Day objects until the biggest submission. The ones that request times that are greater than the array size should trigger a function to populate the array to be just big enough to hold the data. If they're not too frequent, you could even just compute a calendar from start date to end date for every entry, and the time would not be inefficient either.
Hope I helped!
The short answer:
http://en.wikipedia.org/wiki/Lazy_evaluation#Working_with_infinite_data_structures
The long answer:
You do not calculate the list. You do not set the list. You compute the (read-only) list for the (concrete, finite) index N, potentially using cached elements at the index N'
Is there a way to return a series of records in OData by specifying a "Date greater than xxxxx" filter...but using a Date that was previously obtained form an OData feed?
Use Case: Pretend that I want to build a web page that displays a list of the most recently completed online orders. This is what I'm aiming for:
Load the page
Hit my OData service asynchronously, returning the last 100 orders (ordering by date descending so that the most recently completed order shows up first)
Build the HTML on the page using the OData data
Store the MAX date into a global variable (looks like this: /Date(1338336000000)/)
Hit the OData service on a 30 second interval but this time specify a filter to only return records where the order date is greater than the previous MAX Date. In this case: /Date(1338336000000)/
If any records are returned, build the HTML for those records and prepend the items to the previously loaded items.
Where I am struggling is in specifying the Date "greater than" filter. For some reason, the date filters in OData do not seem to play very nice with OData's own native date format. Do I need to convert the date originally obtained into a different format that can be used for filtering?
I want to do something like this:
http://mydomain/Services/v001.svc/Orders?$filter=close_dt%20gt%201338336000000
FYI: I'm using V2
Figured this out.
OData V2 out-of-the-box returns dates out of SQL in JSON Date format like so:
/Date(1338282808000)/
However, in order to use a date as a filter within an OData call, your date has to be in EDM format, looking like this:
2012-05-29T09:13:28
So, I needed to get the date from my initial OData call, then convert it to the EDM format for use in my subsequent OData calls, which look like this:
/Services/v001.svc/Orders?$filter=close_dt gt DateTime'2012-05-29T09:13:28'
I ended up creating a javascript function that does the formatting switcharoo:
function convertJSONDate(jsonDate, returnFormat) {
var myDate = new Date(jsonDate.match(/\d+/)[0] * 1);
myDate.add(4).hours(); //using {date.format.js} to add time to compensate for timezone offset
return myDate.format(returnFormat); //using {date.format.js} plugin to format :: EDM FORMAT='yyyy-MM-ddTHH:mm:ss'
}
A couple of notes:
The JSON format does not seem to adjust for timezone, so the date returned does not match the date I see in my database. So I had to add time manually to compensate (someone please explain this).
I am using the date.format.js plugin which you can download here for formatting the date and adding time.
In OData V4 date filtering format has changed to $filter=close_dt gt 2006-12-30T23:59:59.99Z
For example
http://services.odata.org/V4/OData/OData.svc/Products?$filter=ReleaseDate%20gt%202006-12-30T23:59:59.99Z
For previous versions of OData see previous answers
If you use the datetime logic, you can do lt or gt.
e.g.
...mydomain/Services/v001.svc/Orders?$filter=close_dt gt datetime'20141231'
Just an FYI: in V3 of the protocol the non-tick-based datetime format is now the default:
http://services.odata.org/Experimental/OData/OData.svc/Products%280%29?$format=application/json;odata=verbose&$select=ReleaseDate
..."ReleaseDate":"1992-01-01T00:00:00"...
I will just try to make the answer of #avitenberg more clear:
var date= DateTime.Now;
//Convert time to UTC format
$"filter={close_dt} gt {date:yyyy-MM-ddTHH:mm:ss.FFFZ}";
See Microsoft: