This question already has answers here:
Parse a date from unformatted text in SQL
(4 answers)
Closed 8 years ago.
I have a Date field in a table that is an int. The value looks like this: 20130618 I want to be able to convert that to an actual date like 06/18/2013 so I can do date calculations on it. How do I convert that field?
select convert(date, left(20130618, 8), 101)
or
select convert(date, cast(20130618 as char(8)), 101)
Related
This question already has answers here:
Convert Unix timestamp to timestamp without time zone
(1 answer)
How to convert Unix epoch to a timestamp
(1 answer)
Closed 9 months ago.
I have a table with creation timestamps as decimals and am trying to convert to date data type. When I go to cast as date I get the following error message: "ERROR: cannot cast type double precision to date". []
cast(creation_timestamp as date)
This question already has an answer here:
Alter the timestamp format in Postgres
(1 answer)
Closed 1 year ago.
I need to combine values from two columns into one and then remove the colons, spaces and hyphens.
SELECT
documentation.nsma1_date + documentation.nsma1_time AS "Start Date"
FROM
documentation
This returns column Start Date with data 2021-01-20 09:09:00
I have tried to get it to return 20210120090900 without any luck. Any idea how to do this? I have tried the REGEXP_REPLACE and FORMAT but to no avail.
Use to_char() from here Data formatting
--Assuming 2021-01-20 09:09:00 is timestamp
select to_char('2021-01-20 09:09:00'::timestamp, 'YYYYMMDDHHMISS');
to_char
----------------
20210120090900
UPDATE
select
to_char(documentation.nsma1_date + documentation.nsma1_time,'YYYYMMDDHHMISS') AS "Start Date";
This question already has answers here:
Convert pyspark string to date format
(6 answers)
Closed 2 years ago.
I would like to convert a spark dataframe string column of 'yyyyMMdd' to date format with spark session (spark) - not spark context.
Since I'm not working with spark context (sc), I cannot use the following code, although it would precisly do what I'd like it to do:
.withColumn("column1",DF.to_date(F.col("column1"),"yyyyMMdd"))
As I do not want to convert the column to timestamp, I also don't want to use the following code:
.withColumn("column1", unix_timestamp(col("column1"), "yyyyMMdd").cast("timestamp"))
The final goal is to replace the former string column by the date formatted column.
Many thanks in advance!
the following code works fine:
.withColumn("column1", to_date(DF["column1"], 'yyyyMMdd'))
Thanks for your attention!
This question already has answers here:
How to display date in HH:mm:ss format in JasperReports?
(6 answers)
Create a calendar to pick dates (and time) in Jasper server
(1 answer)
Closed 7 years ago.
I have a jasperreport with datefrom ,dateto, rundate as input parameters.Class type java.util.date. I want to change date format to DD/MM/YY from MM/DD/YY.So what changes do i need to do?
I suggest to use the xml view and try something like this:
new SimpleDateFormat("DD/MM/YY").format($P{datefrom})
This question already has an answer here:
Changing a nvarchar column into a Date format [closed]
(1 answer)
Closed 9 years ago.
How do I convert Nov 28 2012 3:56PM into yyyy-mm-dd HH:MM:SS. I have a column with incorrectly formatted dates and I need to change the format.
CONVERT (datetime, 'Nov 28 2012 3:56PM', 120)
That should work, more info: http://msdn.microsoft.com/en-us/library/ms187928.aspx
Assuming that you want convert a DATE to VARCHAR, this query maybe will be useful:
SELECT CONVERT(VARCHAR(50),CAST('Nov 27 2012 3:56PM' AS DATETIME),120)
In your case, for example, if you field date is FIELD then your query will be:
SELECT CONVERT(VARCHAR(50),FIELD,120)
You can try this here.
120 is a DateStyle for yyyy-mm-dd hh:mi:ss(24h)
Note: the size of VARCHAR it depends on the format you have chosen.