I have 2000+ rows returned with the query below but the date needs to be changed so it's more readable. Is there a way to convert the date from being returned as 20140511 to DD-MM-YYYY in the query below?
Select Jobname AS OptimiseJobs, RunDate AS Date
from tablename
where jobname like '%Optimise'
thanks!
IF you are using SQL server then try below query:
SELECT Jobname AS OptimiseJobs,
CONVERT(varchar(20),CONVERT(date, CONVERT(varchar(8), RunDate), 112),105) AS Date
FROM tablename
WHERE jobname LIKE '%Optimise'
In sql-server
Select Jobname AS OptimiseJobs, cast(RunDate as date) AS Date
from tablename
where jobname like '%Optimise'
Demo
Related
Below is a script i am trying to run in Presto; Subtracting today's date from an integer field I am attempting to convert to date. To get the exacts days between. Unfortunately, it seems the highlighted block does not always convert the date correctly and my final answer is not correct. Please does anyone know another way around this or a standard method on presto of converting integer values to date.
Interger value in the column is in the format '20191123' for year-month-date
select ms, activ_dt, current_date, date_diff('day',act_dt,current_date) from
(
select ms,activ_dt, **CAST(parse_datetime(CAST(activ_dt AS varchar), 'YYYYMMDD') AS date) as act_dt**, nov19
from h.A_Subs_1 where msisdn_key=23480320012
) limit 19
You can convert "date as a number" (eg. 20180527 for May 27, 2018) using the following:
cast to varchar
parse_datetime with appropriate format
cast to date (since parse_datetime returns a timestamp)
Example:
presto> SELECT CAST(parse_datetime(CAST(20180527 AS varchar), 'yyyyMMdd') AS date);
_col0
------------
2018-05-27
You can use below sample query for your requirement:
select date_diff('day', date_parse('20191209', '%Y%m%d'), current_timestamp);
I want to show date in string format as current month name(String) and year(e.g -> SEPTEMBER, 2019). How to write query for this in PostgreSQL?
I tried this query:
select
date(date_trunc('month', current_date));
but it gives me only current months starting date.
Try to_char() and add the year formatter to the string like this:
SELECT to_char(current_date, 'MONTH YYYY')
This will return:
SEPTEMBER 2019
Here's a sqlfiddle
If you want to format the output of a DATE value, use to_char()
select to_char(current_date, 'Month, yyyy');
we can do it like this also in Postgresql -
SELECT TO_CHAR(NOW() :: DATE, 'Month , yyyy');
output - September, 2019
I'm trying to import data from a superoffice caesar crm SQL database.
In this database there is a column called CreateDATE which is a float.
What is the proper way to convert this to yyyy-MM-dd hh:mm:ss format?
The column
I tried something like this but it's not matching the date seen in the program so I'm guessing there something more to this?
Figured it out.
Select
dateadd(d,UpdateDATE,'1899-12-30')
from Activity where CustomerID = xxx order by UpdateDATE desc
Use CAST or CONVERT as the below:
DECLARE #DateVal DATETIME = '2016-08-12 13:57:15.347'
SELECT CAST(#DateVal AS FLOAT) -- 42592,5814276235
DECLARE #FloatVal FLOAT = 42592.5814276235
SELECT CAST(#FloatVal AS DATETIME) -- 2016-08-12 13:57:15.347
My first query is:
SELECT distinct wfc_request_job_id,wfc_request_job_info,
replace(iso_cc,';',' ') as "iso_cc",to_char(wfc_request_start_ts,'yyyy-MM-dd HH:mm:ss') as ts,
sent_message_count,
(link_object_count + poi_object_count + point_address_object_count) as request_object_count
FROM wfc_request_job
where
wfc_request_job_id=173526;
This returns ts as 2015-08-16 03:08:59
Second Query:
SELECT wfc_request_job_id,wfc_request_start_ts,wfc_request_end_ts,replace(iso_cc,';',' ') as "iso_ccs",sent_message_count,wfc_queue_name
FROM wfc_request_job
where
to_char(wfc_request_start_ts,'YYYY-MM-DD') >= to_char(to_date('08/16/2015','MM/DD/YYYY'),'YYYY-MM-DD')
and to_char(wfc_request_start_ts,'YYYY-MM-DD') <= to_char(to_date('08/16/2015','MM/DD/YYYY'),'YYYY-MM-DD')
order by wfc_request_job_id desc
This returns ts of the job id mentioned above as - "2015-08-16 15:58:59.809+02"
How can I make both the queries return ts in UTC+02 - i.e. same timezone
The data type of wfc_request_start_ts is - timestamp with timezone
I changed to queries to have the format HH24:MI:SS however that did not help. Please note that the webapp using these queries will be opened in both Germany and USA.
According to postgresql manual to_char there is TZ (and OF as of v9.4) template patterns for Date/Time formatting.
Therefore in query you need to add it so
postgres=# select to_char(now(),'yyyy-MM-dd HH24:mm:ss TZ');
to_char
------------------------
2015-08-19 12:08:56 CEST
(1 row)
Also, make sure you specify timezone when converting
so instead
to_date('08/16/2015','MM/DD/YYYY')
use
TIMESTAMP WITH TIME ZONE '2015-08-16 00:00:00+02';
in second query.
I have a query that produces date in the datetime format... see below.
UPDATE WCV_3
SET VISIT_1= #TEMP2.[FIRST SERVICE DATE]
FROM WCV_3
JOIN #TEMP2 ON #TEMP2.UNIVERSALMEMBERID= WCV_3.UNIVERSALMEMBERID
WHERE #TEMP2.VISIT_CNT= 1
returns this: 2013-01-03 00:00:00.000
What is the correct CONVERT statement to use and where do I place it in this query to return the DATE only and not the Time part?
I want just 2013/01/03
UPDATE WCV_3
SET VISIT_1= cast(#TEMP2.[FIRST SERVICE DATE] as date)
FROM WCV_3
JOIN #TEMP2 ON #TEMP2.UNIVERSALMEMBERID= WCV_3.UNIVERSALMEMBERID
WHERE #TEMP2.VISIT_CNT= 1
You can use a cast to change the datetime to just a date if your using sql server 2008 +
Select Cast(getdate() as date)