Unable to sort datetime using variable computed from datetime string - jasper-reports

I am trying to sort a table by datetime in descending order. I currently am trying to use a variable to be the field to be used in sorting.
Example data:
header A
datetime
First
01 Jan 2021
Second
17 Aug 2021
I created a variable, as seen below,to try to sort the records.
After creating the Long variable from the DATEVALUE expression, after converting to string, it shows null when I load it into preview. Also, it does not sort properly after using it as a sort field.
Some help is much appreciated.

The dataset included the epoch of the date. I used that to sort.

Related

Tableau Date function and Y0Y comparsion

I have Column that is in String format such as 2018-03 and I want to convert this to Date format in tableau. Once I have convert these 4 years data I want to compare 2019 data with 2018 and 2021 data with 2020s
To convert to a date use the DATE function:
DATE(LEFT([DateField],5)+RIGHT([DateField],2)+"01")
Check here to see 2 different ways to do YoY - do whichever works better for your use case.
Assuming that 03 in your date 2018-03 corresponds to month, you can convert the string column to date column with the following calculation, where my_date is your string column
DATE(DATEPARSE("yyyy-MM", [my_date]))
See the results
Note, if however, 03 is quarter, use this calculation instead
DATE(DATEPARSE("yyyy-qq", [my_date]))

best way insert time with zone JavaScript postgres 9.6

What is the best way to insert the now() date time in postgresql using JavaScript? I've followed some answers but nothing clear, I'd like to find pure JavaScript method, and not with moment.js
It would be so much better if you inserted the table's create SQL code, probably part of your application's code in javascript and more information about the situation you're in to your question, in order for people who want to help, to better understand it.
Assuming you have a table with a createdAt column which its type is TIMESTAMP and you want to fill the query below with proper value for :nowValue which is current date and time, and you don't want to use Postgres's built in functionalities (like CURRENT_TIMESTAMP) or any other javascript library (like moment):
INSERT INTO "myTable" ("createdAt") VALUES (:nowValue)
First you have to init a new Date object:
const nowValue = new Date();
Then you can convert the newly created object to string and use it in your query using different methods which return different values:
nowValue.toDateString(); // "Fri Jan 12 2018"
nowValue.toGMTString(); // "Fri, 12 Jan 2018 11:09:43 GMT"
nowValue.toISOString(); // "2018-01-12T11:09:43.153Z"
nowValue.toLocaleDateString(); // "1/12/2018"
nowValue.toLocaleString(); // "1/12/2018, 2:39:43 PM"
nowValue.toUTCString(); // "Fri, 12 Jan 2018 11:09:43 GMT"
Some of the above methods only outputs the date and not the time, which will make column's time value to be set to 00:00:00.000000.
For more detailed information about these methods and how they are different see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Hive datatype confusion

I have a large data and in that one field be like Wed Sep 15 19:17:44 +0100 2010 and I need to insert that field in Hive.
I am getting troubled for choosing data type. I tried both timestamp and date but getting null values when loading from CSV file.
The data type is a String as it is text. If you want to convert it, I would suggest a TIMESTAMP. However you will need to do this conversion yourself while loading the data or (even better) afterwards.
To convert to a timestamp, you can use the following syntax:
CAST(FROM_UNIXTIME(UNIX_TIMESTAMP(<date_column>,'FORMAT')) as TIMESTAMP)
Your format seems complex though. My suggestion is to load it as a string and then just do a simple query on the first record until you get it working.
SELECT your_column as string_representation,
CAST(FROM_UNIXTIME(UNIX_TIMESTAMP(<date_column>,'FORMAT')) as TIMESTAMP) as timestamp_representation
FROM your_table
LIMIT 1
You can find more information on the format here: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
My advice would be to concat some substrings first and try to convert only the day, month, year part before you look at time and timezone et cetera.

Xpath current date

I have a webpage where a row displays name, relation and date. I want to search for the matching row as per my values. Using Xpath, I have built the below mentioned code. The only problem is the last part (the date). I want to pick up the current date and fit it into the search query..i.e. instead of 30 Sep 2013, I want it to search for 01 Oct 2013 (assuming today is this date).
Any clue how can i do that??
$x('//tr[descendant::b[text()="text1"] and descendant::a[#class="bill" and text()="for Automation"] and descendant::td[text()="30 Sep 2013"]]')
You have to build the expression dynamically and append the date string at the end based on some date object. The specific implementation depends on which programming language you're using

How to convert from string to date data type?

I am uploading data from a csv file to MongoDB. It is taking OrderDate as string data type due to which facing problems while creating reports using a BI tool.
I have about 10000 records in my collection.
Could anyone help me how can I change the data Type of OrderDate to Date with a single query?
I don't think that you can change field's type with single query. The easiest way is to convert data strings into Date format using ISODate function during the insertion. But, if you want to process the data you already inserted, you can do it with the following code using mongodb console:
db.collection.find().forEach(function(element){
element.OrderDate = ISODate(element.OrderDate);
db.collection.save(element);
})
This code will process each element in your collection collection and change the type of Orderdate field from String to Date.
db.messages.find().forEach(function(doc) {
doc.headers.datestamp = new Date(Date.parse(doc.headers.Date.toString()));
db.messages.save(doc);
})
This worked well to convert this sort of text:
Tue, 14 Nov 2007 03:22:00 -0800 (PST)
The text is from an email archive known as the Enron Corpus.