Can I use dt_txt instead of dt for date using flutter? - flutter

I've been having problems rendering the dates even after formatting the dates.. I'm using openweather api for 3 hours forecast and trying to render the date as dt_txt format. Can I just use dt_txt for date instead of dt converting to simple date?

Without knowing how you retrieve the other data from the list it is hard to point you in the right direction. But I'll give it a try.
According to the docs cnt means that the list has 40 objects in your case.
You're only using the first one [0] over here:
date: DateTime.fromMillisecondsSinceEpoch(
json['list'][0]['dt'] * 1000,
isUtc: false)
If you want to use dt_text from each object you need to do something this using an index.
json['list'][index]['dt_txt']
A simple example using a for loop could also be:
List<String> dateList = [];
for(var data in json['list']){
dateList.add(data['dt_txt']);
}

Related

Get correct date from excell on flutter

Hello guys I'm having a little hard time figuring this out.
So I have a small excell that I'm putting some information there(adding and requesting)
The problem is when I'm trying to get the date as string, and add it as DateTime.
Always the same error "Invalid Date Format"-
I have my dates on excell, as Simple Text saved as "20-06-2022", and displaying that on flutter with "user[index].date", all ok. The problem is that I want to compare the dates with a random day.
I've tried
DateTime.parse(users[index].date); // not working
Text(users[index].date); // not working ( shows random numbers as 44734)
The DateTime.parse method only accepts specific formats that are listed in the documentation.
Since yours is not one of those, you need to create a DateFormat instance of your own and use that one to parse
void main() {
final text = '20-06-2022';
final format = DateFormat('dd.MM.yyyy');
final date = format.parse(text);
print(date);
}

Google Sheets - DATE format not working on imported Date in TEXT format

I text based .csv file with a semicolon separated data set which contains date values that look like this
22.07.2020
22.07.2020
17.07.2020
09.07.2020
30.06.2020
When I go to Format>number> I see the Google sheets has automatic set.
In this state I cannot use and formulas with this data.
I go to Format>number> and set this to date but formulas still do not see the actual date value and continue to display an error
Can someone share how I can quickly activate the values of this array so formulas will work against them?
I would be super thankful
Where the date are in column A, starting in cell A1, this formula will convert to DATE as a number, after which you apply formatting to Short Date style.
=ARRAYFORMULA(IF(A1:A="",,DATE(RIGHT(A1:A,4),MID(A1:A,4,2),LEFT(A1:A,2))))
Hopefully(!) the dates stay as text, otherwise Google Sheets would sometimes detect MM/dd/yyyy instead of dd/MM/yyyy, and you won't be able to distinguish between July 9th and September 7th in your example.
Solution #1
If your locale is for instance FR, you can then apply
=arrayformula(if(A1:A="";;value(A1:A)))
solution#2
you can try/adapt
function importCsvFromIdv1() {
var id = 'the id of the csv file';
var csv = DriveApp.getFileById(id).getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csv);
csvData.forEach(function(row){
date = row[0]
row[0] = date.substring(6,10)+'-'+date.substring(3,5)+'-'+date.substring(0,2)
})
var f = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
f.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
First thanks to those that suggested a fix. I am not really a programmer and get cold sweats when I see suggesting of running scripts to solve simple problems. Sorry guys.
So the (non programmer) solution with the dates was to do a find/replace (CTRL + H) and replace all the (.)dots with (/)slashes, then to make sure the column is formatted as a date, then Google finally understands it as a date.
With the accounting values as well, I had to do the same find/replace to remove all the ' between thousands, then google woke up and understood them as numbers.
I am significantly underwhelmed by this from Google. They are getting too fat and lazy. They need some competition.

Power Query From Web dynamical DAX

I am courious about how to make M coding more dynamically when finding data. Currently i am trying to gather day-to-day stock data. I am Currently using this line of M-code to get the data
= Web.Page(Web.Contents("https://finance.yahoo.com/quote/MATAS.CO/history?period1=1372377600&period2=" & "1600214400" & "&interval=1d&filter=history&frequency=1d"))
The part "1600214400" is supposed to change each day. However, I tried different ways to make this dynamic. For instance, I used Advanced mode when using Get From Web. But that also failed. I also tried to use other queries, tables and output from functions. Does anyone have any idea or thoughts about to make this part dynamic?
I have enclosed a picture on how it looks on advanced.
I Googled this problem and some pictures illustrated the possibility of using parameters when using From Web. But I do not have that feature...
You can create a small function (see unixTimestampForStartOfToday in code below), which gives you a Unix timestamp in seconds for the start of "today" (where "today" is the date (per UTC) on which the code is running.
You can then use it as the value of the period2 query string parameter -- meaning period2 should always reflect the current date (per UTC).
let
unixTimestampForStartOfToday = () as number =>
// Should return the unix timestamp for today's date (as per UTC)
// at 00:00 hours.
let
todayFloored = DateTime.Date(DateTimeZone.FixedUtcNow()),
unixTimestampInSeconds = Duration.TotalSeconds(todayFloored - #date(1970, 1, 1))
in unixTimestampInSeconds,
Source = Web.Page(
Web.Contents("https://finance.yahoo.com/quote/MATAS.CO/history", [
Query = [
period1 = "1372377600",
period2 = Number.ToText(unixTimestampForStartOfToday()),
interval = "1d",
filter = "history",
frequency = "1d"
]
])
)
in
Source

Format date and add month to it

I'm currently working with embarcadero c++, this is the first time I'm working with it so it's completely new to me.
What I'm trying to achieve is to get the current date, make sure the date has the "dd/MM/yyyy" format. When I'm sure this is the case I want to add a month to the current date.
So let's say the current date is 08/18/2016 this has to be changed to 18/08/2016 and then the end result should be 18/09/2016.
I've found that there is a method for this in embarcardero however I'm not sure how to use this.
currently I've only been able to get the current date like this.
TDateTime currentDate = Date();
I hope someone will be able to help me out here.
I figured it out.
After I've searched some more I found the way to use the IncMonth method on this page.
The example given my problem is as follows:
void __fastcall TForm1::edtMonthsExit(TObject *Sender)
{
TDateTime StartDate = edtStartDate->Text;
int Months = edtMonths->Text.ToInt();
TDateTime NextPeriod = IncMonth(StartDate, Months);
edtNextPeriod->Text = NextPeriod;
}
After looking at I changed my code accordingly to this
TDateTime CurrentDate = Date();
TDateTime EndDate = IncMonth(CurrentDate, 1);
A date object doesn't have a format like "dd/MM/yyyy". A date object is internally simply represented as a number (or possibly some other form of representation that really isn't your problem or responsibility).
So you don't have to check if it's in this format because no date objects will ever be in this format, they simply don't have a format.
You will have to do additions/subtractions on the Date object that the language or library gives you, THEN (optionally) you can format it to a human-readable string so it looks like 18/08/2016 or 18th of August 2016 or whatever other readable format that you choose.
It might be that the TRANSFER of a date between 2 systems is in a similar format, but then formatting the date like that is entirely up to you.
As for how to do that, the link you posted seems like a possible way (or alternatively http://docwiki.embarcadero.com/Libraries/Berlin/en/System.SysUtils.IncMonth), I'm afraid I can't give you an example as I'm not familiar with the tool/language involved, I'm just speaking generically about Date manipulations and they should ALWAYS be on the raw object.

Export Calendar Date to spreadsheetout - Time Stripped off - Google Script

I am using Google Script to export some calendar events to a spreadsheet; the relevant portion of my script is below:
var details=[[mycal,events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), events[i].getStartTime(), myformula_placeholder, ('')]];
var range=sheet.getRange(row,1,1,7);
range.setValues(details);
This code works but the "time" that is put into the spreadsheet is a real number of the form nnnnn.nn. On the spreadsheet itself the date looks great using the integer to the left of the decimal (eg 10/15/2017) but the decimals are part of the value and therefore are part of the spreadsheet value.
My script drops the data into a sheet in my workbook, and another sheet reads the rows of data with the above date types, looking for specific date info from the other sheet using the match function (for today()). That would work fine if I could get rid of the decimals.
How can I use what I have above (if I stray far from what I have found works I will be redoing hours of work) but adding just what is needed to only put into the output spreadsheet the whole number portion so I have a pure date that will be found nicely by my match function using today()?
I have been digging, but errors abound in trying to put it all together. "Parse" looked like a good hope, but it failed as the validation did not like parse used within getStartTime. Maybe I used it in the wrong manner.
Help would be appreciated greatly.
According to the CalendarApp documentation, getStartTime() generates a Date object. You should be able to extract the date and time separately from the date object:
var eventStart = events[i].getStartTime(); // Returns date object
var startDate = eventStart.toDateString(); // Returns date portion as a string
var startTime = eventStart.toTimeString(); // Returns time portion as a string
You could then write one or both of these to your spreadsheet. See the w3schools Javascript Date Reference for more information:
http://www.w3schools.com/jsref/jsref_obj_date.asp
If you If you want to specify the string format, you can try formatDate in the Utilities service:
https://developers.google.com/apps-script/reference/utilities/utilities#formatdatedate-timezone-format
You could just use the Math.floor() function
http://www.w3schools.com/jsref/jsref_floor.asp
which will round the real number to an integer. Your line would then read:
var details=[[mycal,events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), Math.floor(events[i].getStartTime()), myformula_placeholder, ('')]];