I am trying to convert a string to date in Redshift.
select to_date('Fri Apr 03 00:00:07 2020','Dy Mon DD hh24:mi:ss YYYY')
I am getting an issue Invalid operation: Invalid date format: Specified day twice.
Is it not possible to mention both Day name and Day of month as a number in the same date string?
I am following this reference for date formats in Redshift
So you are specifying the date twice in your format string - day of week and day of month. Which is Redshift to use if they are in conflict? The reference you provided is general in nature, specifying both input and output format patterns (converting to a string you may want both date and day of week). If you just want to ignore the day of the week in the input string just use the format string 'XXX Mon DD hh24:mi:ss YYYY'.
Related
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]))
I want to fetch the date from the database and then need to manipulate on that date to display the due date in the jasper report.
Table name is: ACCOUNTINGLOCATION
Column name: CURRENTACCOUNTINGDATE (dd//mm//yyyy time)
Once we fetch the CURRENTACCOUNTINGDATE from databse , Use this date as base to generate the due date in the text field. Due date is nothing but the next month 14th.
Suppose the CURRENTACCOUNTINGDATE = 21.01.2019 then in the report I should display the value as 14.02.2019( dd/mm/yyyy)
For Jan the due date will be feb 14. for Feb due date will be march 14 and so on.
Can you please help me with this code.
You can use builtin date/time functions to compute the date:
<textFieldExpression><![CDATA[EDATE(DATE(YEAR($F{CURRENTACCOUNTINGDATE}), MONTH($F{CURRENTACCOUNTINGDATE}), 14), 1)]]></textFieldExpression>
With DATE(YEAR(..), MONTH(..), 14) you get 14th on the current month, and then the EDATE function is used to add a number of months (1 in this case) to the date.
I am interested in converting a date column with a string mm/dd/yyyy hh:mm:ss to an hour format using Talend Open Studio. I want the hour of the day from the Date column.
If the String has already been converted to a Date, you could retrieve the hour of the day with formatting in tMap:
TalendDate.formatDate("HH",myDate)
This will return a String with the hour of the day.
If the String has not been converted, I suggest converting it before - it is always better to have a Date and work on the Date type than doing String processing.
I'm having a problem reading dates from a database using JPA. I'm using EclipseLink and PostgreSQL
I've populated my database from a CSV file, witch had dates as strings (in this format: 6/30/2009-23:59:56). I used the following snipet to convert it to a Date object:
public static Date parseDate(String s){
DateFormat formatter = new SimpleDateFormat("d/M/yyyy-k:m:s");
try {
return new Date( ((java.util.Date)formatter.parse(s)).getTime() );
} catch (ParseException ex) {
Logger.getLogger(Type.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
The date is correctly converted and stored in the database as expected. Here is how i map the Date object to the database:
#Column(name="data_ts", nullable=false)
#Temporal(TemporalType.TIMESTAMP)
private Date dataTs;
The problem seems to happen when i try to read the Date from the database to use it in a chart(Highcharts). The record with that same timestamp above get read as:
Mon Jun 06 23:59:56 BRT 2011 and it's timestamp as 1307415596000
Note that it is in Brazilian Time(+3h), so the timestamp (that is calculated from GMT) is 3 hours shifted. Once ploted, the timestamp turns to point to 07/06/2011 02:59:56
Here's an example:
List<TimedataEnt> timeData = currentWellsite.getTimeData();
String debug = timeData.get(timeData.size()-1).getDataTs().toString() + ">>>" + timeData.get(timeData.size()-1).getDataTs().getTime();
where currentWellsite is and JPA Entity, and getDataTs() returns a java.util.Date object.
The string turns out to be "Tue Jun 30 23:59:56 BRT 2009>>>1246417196000"
How do I tell JPA not to convert the timestamp read from the database?
As said, Date and Timestamps have no timezone consideration. It seems that the issue is caused because Java considers that the time it reads from the database is the current default timezone.
So, if the database contais 2011-04-04 14:00:00 and my current timezone is +3, assigning that to java Date will generate 2011-04-04 14:00:00 BRT time(+3), with a timestamp shifted 3 hours (since timestamps are caclulated from UTC).
Solved the issue by getting an calculated timestamp:
long ts = myDate().getTime() + TimeZone.getDefault().getRawOffset();
It's important to say that getRawOffset() does not take Daylight Saving periods in consideration. For that, use getOffset()
Your date is 6/30/2009-23:59:56. I read that as 30 june 2009, 23:59:56. So the format to parse it should be M/d/yyyy-HH:mm:ss or M/d/yyyy-kk:mm:ss (depending on if your hours go from 1 to 24 or from 0 to 23). But definitely not d/M/yyyy-k:m:s: the month comes before the day.
Also, a Timestamp doesn't have any time zone. It's a universal instant in time. It's only when you display its value that the timezone is important, because then you have to choose which time zone to use to display the time. Use a DateFormat with the appropriate timezone set to display your timestamp.
Your issue seems to be that you are storing your Timestamp (which does not have a timezone) into a java.util.Date (which has a timezone offset).
If you want control over how the timezone is set, then store your Timestamp as a java.sql.Timestamp, or use your own #Converter.
In general Calendar should be used in Java instead of java.util.Date, which is for the most part deprecated. Calendar also has a Timezone, so you may have similar issues.
I am trying to get the date from SQLite. I am getting timestamp in coredata, but I need to see the date. What is the command to get the timestamp converted into YYYY-MM-DD format? My query is:
SELECT ZDATE FROM ZWEATHER
Zdate is datetime.
You may be looking for the DATE() function, as seen in the SQLite manual:
SELECT date(ZDATE);
The first thing to understand is that SQLite has no date type. It has no time type either.
It only offers some time functions. The page Piskvor links to is what you need. You enter the date and/or time in your database as a string following one of a few formats available:
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
Or as a floating point value representing the Julian day number.