Regardless of the time zone I have set on my google sheets doc =TODAY() produces the date but the time stays at midnight 0:00.
I have checked the settings to ensure TODAY() is set to update on change, I have tried formatting the cell as date-time, etc. Nothing seems to work. Any ideas?
what you need is timestamp script:
function onEdit(e) {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) { // Sheet name
var r = s.getActiveCell();
if( r.getColumn() == 1 ) {
var nextCell = r.offset(0, 1);
var newDate = Utilities.formatDate(new Date(),
"GMT+8", "MM/dd/yyyy hh:mm:ss"); // Format
nextCell.setValue(newDate);
}}}
how to deploy a script:
now you can close the apps script tab/window and enjoy the timestamp script running automatically whenever you type something in A column B column gets timestamped
You need to use the =NOW() function, =TODAY() will just fetch the date. The default time when you transfer a regular date value to a time stamp is midnight.
Related
I'm struggling with formatting a date to insert into a calendar. I'm working on an Ionic project and I'm attempting to leverage moment.js timezones. The data is being passed into the application in several pieces. I am receiving a millisecond date time stamp, a 24-hour string for time and a string of the timezone. The date does not contain the time. What I want to achieve is creating a date object from these pieces and then converting the date into the user's local timezone to add it to their device calendar.
example of data passed to app
The date of the event: August 14, 2018 17:00
time = 17:00
date = 1534204800
timezone = AEDT
The destination timezone is based on the user's location.
let timeFormatter = new Date();
timeFormatter.setMilliseconds(date);
let momentHrMin = moment(timeFormatter.toDateString() + " " + time);
//WP sever is on GMT get the day, month and yr
let momentTZDate = momentTz.unix(date);
momentTZDate.tz('GMT');
let day = momentTZDate.days();
let month = momentTZDate.month();
let yr = momentTZDate.year();
//set the correct timezone on the ecpoh/unix DATE with momentTz.
momentTZDate.tz(this.eventDetails.eventDetail.timezoneOffset);
// Lastly set the date so the timezone conversions are correct
momentTZDate.set(
{
day: day,
month: month,
year: yr,
hour: momentHrMin.hour(),
minute: momentHrMin.minute(),
second: 0,
millisecond: 0
}
);
I found the cause of my struggles with the timezones. The abbreviated AEDT is not an accepted value for Moment.tz. AEDT could represent multiple timezones. For example, American Eastern, Australian Eastern, etc... Simply changing momentTZDate.tz("AEDT"); to momentTZDate.tz("Australia/Brisbane"); fixed my issue. Below is my typescript code I used to get through this issue. I won't say its the best but it works.
private getCalDate(date:number, time: string): Date {
// create an object in which the hours and minutes can be parse from(do to free text entry on the backend moment handles different inputs)
let timeFormatter = new Date();
timeFormatter.setMilliseconds(date);
let momentHrMin = moment(timeFormatter.toDateString() + " " + time);
//WP sever is on GMT get the day, month and yr
let momentTZDate = momentTz.unix(date);
momentTZDate.tz('GMT');
let day = momentTZDate.days();
let month = momentTZDate.month();
let yr = momentTZDate.year();
//set the correct timezone on the ecpoh/unix DATE with momentTz.
momentTZDate.tz("Australia/Brisbane");
// Lastly set the date so the timezone conversions are correct
momentTZDate.set(
{
day: day,
month: month,
year: yr,
hour: momentHrMin.hour(),
minute: momentHrMin.minute(),
second: 0,
millisecond: 0
}
);
return momentTZDate.toDate();
}
I've imported a csv file in my spreadsheet which containing a date in this format
yyyymmdd
(20161018 for today )
To use this date in my new spreadsheet I use this formula
CELL T49 = 20161018
=DATEVALUE(CONCATENATE(left(T49;4);"/";mid(T49;5;2);"/";right(2)))
I was wondering if there is a more simple way to convert a text date to a spreadsheet date
It becomes relevant because you can not use concatenate in an "ArrayFormula"
You could make your own function (cut/paste the script below into Tools>Script Editor) and then use =DATEME(T49)
function DATEME(input) {
var input = input.toString();
var year = input.substring(0,4);
var month = input.substring(4,6);
var day = input.substring(6);
//JavaScript months are 0-11
return new Date(year,month-1,day) ;
}
=DATEVALUE(TEXT(20161018;"0000-00-00"))
next format cell as date.
TEXT function converts number format to string looking like date:
2016-10-18
DATEVALUE converts a provided date string in a known format to a date value
My default date setting in Fiori launchpad is "dd.MM.yyyy, HH:mm". Whenever I get the date from the date picker placed in view, I am getting the date in the above format.
Now I want to send this date to backend through ODataModel which generally accepts date in XML date format (e.g. "2014-12-30"). I tried the below code, but it did not work.
var fromDate = this.byId("fromDate").getValue(); // "30.12.2014, 10:36"
var oDateFormat = DateFormat.getDateTimeInstance({ pattern : "yyyy-MM-dd" }); // DateFormat required from "sap/ui/core/format/DateFormat"
var subFromDate = oDateFormat.format(new Date(fromDate)); // "0NaN-NaN-NaN".
When I check in debugger mode, the value in subFromDate is "0NaN-NaN-NaN". Please provide your valuable suggestions.
You can use getDateValue() method instead of getValue.
var fromDate = this.byId("fromDate").getDateValue(); // returns a JS date object
var oDateFormat = DateFormat.getDateTimeInstance({ pattern : "yyyy-MM-dd" }); // DateFormat required from "sap/ui/core/format/DateFormat"
var subFromDate = oDateFormat.format(fromDate); // "2014-12-30"
The fromDate isn't correct. When I using new Date("30.12.2014, 10:36"), the console show message " Invalid Date".
I look for more information about "Date" from MDN(link).
new Date(dateString)
String value representing a date. The string should be in a format recognized by the Date.parse() method. The dateString could be '30 12 2014 10:36'.
So you need to replace the '.' and ',' to ' ' in fromDate first.
You can use display format and value format properties of date time picker.
new sap.m.DateTimePicker("ED",{
valueFormat: "yyyy-MM-ddTHH:mm:ss",
displayFormat: "dd-MM-yyyy HH:mm:ss"
});
you can easily get the values using
sap.ui.getCore().getControl("ED").getValue();
I have a datetime column in a table and I want to retrieve data month wise from this date time column. I want to populate a dropdown down list with month name only so that user can search data by month name.
here is my linq code
var filterdate = from dates in _db.entries
where date1 >= dates.PaidOn
where date2 <= dates.PaidOn
select dates;
return View(filterdate);
and how to write the razor view code. please help. I am stuck. I would really appreciate your help. thanks in advance. Gitu
Try following:
var filterdate = from dates in _db.entries
where date1 >= dates.PaidOn
&& date2 <= dates.PaidOn
select dates.PaidOn.Month;
or
var filterdate = _db.entries.Where(i=> date1 >=i.PaidOn && date2 <= i.PaidOn )
.Select(i=>i.PaidOn.Month);
I am working on the application which have 15days free subscription and then it give the expiry message to the user.
I got the expiry date (yyyy-MM-dd format) in login and have to check with current date .
I have tried with the two date object 1st object have current date and 2nd have expiry date.
But i am only get true when both date are same with DateTimeUtilities.isSameDate(date1, date2); function but it only return true if both date are same.
Please anyone help me to solve my problem.
You can find your answer with the following
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");//Your format type
Date todayDate = new Date(HttpDateParser.parse(formatter.formatLocal(System.currentTimeMillis())));//It converts system date in your given format & store in todayDate object
Date expiryDate = new Date(HttpDateParser.parse(expiryDateString));//It Store your expiry date in your expiryDate format
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(todayDate);
cal2.setTime(expiryDate);
if(cal1.before(cal2))
{
// Current date is less than your Expiry date
}
else
{
// Current date is equals and greater your Expiry date
}
You can do the following
boolean expired = (currentDate.getTime()>expiryDate.getTime());
if(expired)
Status.show("Expired");