Google spreadsheets convert text date to spreadsheet date - google-sheets

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

Related

Today() Function in Google Sheets stuck at Midnight

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.

change the datetime format in flutter, to leave it only with the date

I would like to know how I can change the datetime format in flutter, to leave it only with the date.
I also want to know if there is another widget that only contains the date.
Thanks
You can use DateFormat from intl package.
With it you can custom to any format that you need.
Add to pubspec.yaml
dependencies:
intl: ^0.15.7
On Dart code:
import 'package:intl/intl.dart';
final dateFormatter = DateFormat('yyyy-MM-dd');
final dateString = dateFormatter.format(DateTime.now());
Then you can put the string into any widget. Example:
Text(dateString)
About date format: https://www.cl.cam.ac.uk/~mgk25/iso-time.html
Make a new DateTime and get the day from that:
var date = DateTime.now();
var result = "${date.year}/${date.month}/${date.day}";
print(result); // prints 2019/3/6
You can get the day month and year from DateTime object and convert it to string.
DateTime today = DateTime.now();
print(today); // prints 2019-12-15 00:00:00.000
DatetTime date = DateTime(today.year, today.month, today.day).toString().substring(0,10);
print(date); // prints 2019-12-15
hope this helps

Remove time component from TimeInterval in Swift?

I have a time component coming from a Json. I am trying to group objects according to their time posted.
I have a time interval like 1540432146 which is a double.
I am converting it to Date type using
guard let timeInMilliseconds = lastUpdateOn as? Double else {return NSDate()}
let timeInSeconds = timeInMilliseconds / 100000
print(timeInSeconds)
// get the Date
let dateTime = NSDate(timeIntervalSince1970: timeInSeconds)
Hence I am getting 2018-10-25 10:54:20.325076+0900 as the output.
Is it possible to remove the Time component of this and again converting the Date type back to TimeIntervalSincel1970 as I will using it later to sort my elements in an array and it would be easier to compare Double
func getTime(lastUpdateOn:Any) -> NSDate{
guard let timeInMilliseconds = lastUpdateOn as? Double else {return NSDate()}
let timeInSeconds = timeInMilliseconds / 100000
// get the Date
let dateTime = NSDate(timeIntervalSince1970: timeInSeconds)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
let datenew = dateFormatter.string(from: dateTime as Date)
let newDate = dateFormatter.date(from: datenew)
print(newDate)
return dateTime
}
This is the function I tried but it returns value (1970-06-27 15:00:00 +0000) always. What am I doing wrong ?
If your only goal is to compare different dates to see which one comes first, simply convert the Int Unix Timestamps from your JSON to Date objects with:
let aDate = Date(timeIntervalSince1970: Double(timestamp)/1000.0)
You can compare Date objects directly using >, =, <, etc, and the result will compare the dates down to the millisecond.
You can also compare your Unix timestamp values directly and the results will be identical to comparing timestamps that you've converted to Date objects.
If you want to compare Date objects just by month/day/year, its more complicated.
A Cocoa Date ALWAYS represents an instant in time, all over the world. Internally, it's represented as a number of seconds since the iOS "epoch date" (midnight on January 1st, 2001 in UTC) Unix uses a different epoch date, but using "timeIntervalSince1970" and it's variants lets you work with Cocoa Date objects and Unix epoch dates.
There is no such thing as a Date "without a time component". There are various ways you could "normalize" your dates: You can convert a date to a date string that only has the month/day/year; you can force all Date values to exactly midnight on their month/day/year in a given timezone, or you could extract month/day/year DateComponents from your Date. (Search on "DateComponents" in the Xcode help system, and also search for "DateComponents" in the Calendar class reference, as many of the functions that let you do calculations on Dates and DateComponents are provided by the Calendar class.)
Note that the day/month/year that a Unix numeric timestamp falls on is often different depending on your time zone. Right now it's 22:47 EDT on 24 October here in the DC suburbs. I just computed the Unix timestamp for the current time and got 1540435644000. In Japan, 1540435644000 is 25 October. (From my perspective, it's already tomorrow in Japan). So 2 Unix timestamps might be on the same day/month/year in Japan but on different day/month/years where I live, or visa-versa.

Date Range Picker - Calendar Heading Localization Format

When applying localization to the angular date range picker the date format is incorrect for the calendar heading. The date should be displayed as YYYY, MM but is displayed as MM, YYYY. I'm using moment().format('ll') to display the localized format in the text input but using the date range picker locale.format option doesn't have any affect on the calendar date format.
var dateOptions = {
locale: {
format: 'll'
}
};
Updated daterangepicker.js as follows:
// added new var around line 719
var calMonth = moment([calendar[1][1].year(), calendar[1][1].month()]).format("L");
// line 754
html += '<th colspan="5" class="month">' + calMonth + '</th>';
modify daterangepicker.js
line 707
var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
modify it to the format you want.
var dateHtml = calendar[1][1].format("YYYY") + this.locale.monthNames[calendar[1][1].month()];

How to format Date(Time)Picker value to a date only string?

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();

Resources