How to apply date/time sorting on a column which has date/time as string in G1 table in gramex - gramex

I have a G1 table (Gramex) in UI which has columns with date and time but as string.
When the user sorts the respective column with the help of inbuilt sort option, it sorts the data as string not as date.

Approach 1
The easiest way would be if the date and time were formatted like YYYY-MM-DD HH:MM:SS. For example, '2022-09-04 03:02:01'. This is a string that can be sorted consistently with the datetime.
You can create such strings in Python with the datetime.isoformat() function.
Approach 2
If your dates are stored in a different format, e.g. 04-09-2022, etc., then IF the data is loaded from a file, not a database, then you can modify the data with the function: transform to convert the column to the right data format.
For example:
url:
continent:
pattern: /data
handler: FormHandler
kwargs:
url: data.csv
function: data.assign(date_col=pd.to_datetime(data[date_col]).strftime('%Y-%m-%dT%H:%M:%S'))
This converts the date_col (replace this with your date column name) from any date format Pandas recognizes into a YYYY-MM-DD HH:MM:SS type format that is sortable.
If the data is loaded from a database, then you DO need to convert it into a sortable format first.

Related

how to convert time zone of a datetime in google sheets

I have a column, in which datetime in text format "2022-04-12 07:09:10 UTC". I want to change this into IST time zone and convert it into date format only
You'll need to extract the date and time then add on 5h30m. From there you can either wrap it with INT or format the column to show just the date. For the one below, I used INT, which will strip the time after it is converted.
=ARRAYFORMULA(
IF(ISBLANK(A2:A),,
REGEXREPLACE(A2:A,"UTC","")+
TIME(5,30,0)))

How do you select all the rows between two values in SQLite?

I'm building an iOS app where I want to retrieve all the values from my database between two dates that the user picks. So for example, I want all the rows from the 1st of March to the 5th of March. Would look something like
SELECT * FROM MAIN WHERE DATE = '01/03/2020' AND ENDS ='05/03/2020'
So from that I would hope to retrieve all data from the 1st,2nd,3rd,4th and 5th of march. Any ideas on how to do this?
Thank you
Try to use comparison operators like:
DATE >= '01/03/2020' AND DATE <= '05/03/2020'
There are two issues:
Date types:
As Datatypes In SQLite Version 3 says:
2.2. Date and Time Datatype
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
So storing dates in a dd/MM/yyyy format (using the DateFormatter capitalization convention) is problematic because in the absence of a native date type, it’s going to store them as strings, and therefore all comparisons will be done alphabetically, not chronologically, sorting values like 03/10/2009 (or nonsense strings like 02foobar, for that matter) in between the strings 01/05/2020 and 05/05/2020.
If, however you store them as yyyy-MM-dd, then it just so happens that alphabetical comparisons will yield chronologically correct comparisons, too.
SQL syntax:
Once you have your dates in your database in a format that is comparable, then if you have all of your dates in a single column, you can use the BETWEEN syntax. For example, let’s say you stored all of your dates in yyyy-MM-dd format, then you could do things like:
SELECT * FROM main WHERE date BETWEEN '2020-03-01' AND '2020-03-05';
But needless to say, you can’t use this pattern (or any comparison operators other than equality) as long as your dates are stored in dd/MM/yyyy format.
If you want to show all the data that has values of column "date" between this two dates then:
Select *
from MAIN
where `date` between '01.03.2020' and '05.03.2020';
If you want to show all the data that has values of column "ends" between this two dates then:
Select *
from MAIN
where ends between '01.03.2020' and '05.03.2020';
If you want to show all the data that has values of columns "date" and "ends" between this two dates then:
Select *
from MAIN
where ends between '01.03.2020' and '05.03.2020'
and `date` between '01.03.2020' and '05.03.2020';
Here is a demo

Convert SPSS string variable to numeric and date

I have the date variable which is in string format. I need to convert this to numeric or date format. How can I do this?
Example:
var1
2010/07/09
2010/07/16
Thanks,
Tanuvi
If you read in the date value as a string, you can use Transform > Date and Time Wizard to convert it to an SPSS date variable. Although date variables look like dates in various formats, they are actually represented as the number of seconds since 1582 and can consist of calendar and time information.

Delphi 7, Titan BTrieve Components

I am using Delphi 7, and Titan BTrieve to open a Pervasive Table.
It is a TtbTable component.
I am trying to apply the filter on a TimeStamp field with my code as follows:
Date:=InputDate;
DateString:=FormatDateTime('DD/MM/YYYY HH:NN:SS', InputDate);
Table1.Filter:='UPDATEDON > '+chr(39)+DAteString+chr(39);
Table1.Filtered:=True;
The problem is that the filter results are incorrect. It returns records that are before the do not match the filter criteria.
the Table1.Filter, filters the data in TDataSet not in btrieve/pervasive.
the problem is the date in string format... you must use the formar YYYY-MM-DD and not DD-MM-YYYY because the string compare.
in a string compare 17-06-2012 is grater than 16-07-2012, (17>16)
From the look of it, you are comparing strings, not dates.
What version of PSQL are you using? Is the UPDATEDON field defined as a Timestamp in the Btrieve database? If it's a timestamp, values are stored in 8-byte unsigned values representing septaseconds (10^-7 second) since January 1, 0001 in a Gregorian calendar, Coordinated Universal Time (UTC). It is not stored as a string.
Btrieve / PSQL stores dates in the 'YYYY-MM-DD' format.
WHat does a value from the UPDATEDON field look like? To use it as a filter, you need to make sure the filter value looks the same.

issue to query data filtered by Date from fusion table

I'm trying to write a small javascript code to query data filtered by date.
If I write the following sentence in my browser, I can get data :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883"
but if I write the same thing, except I want only data after a certain date :
"http://www.google.com/fusiontables/gvizdata?tq=SELECT Date, Poids FROM 3049883 WHERE Date > 2/29/12"
From the SQL-like API, https://developers.google.com/fusiontables/docs/developers_reference#Select, it should work
I get an error witch is "'internal_error', message:'Could not parse query'"
-Date is a DATETIME format in my fusion table.
-I've tried different format, but I can not get data.
What am I doing wrong?
Thank you very much for your help.
The Date value must be quoted and the format is MM/dd/yy so you must pad single digits with leading zeros.
I had success with:
select Date,Poids from 3049883 where Date >= '02/29/12'
Note: I did not test with gvizdata, just with the FT JSONP API

Resources