简体   繁体   中英

Given day, month and year, calculate weekending date

Given day, month and year as integer columns in the table, calculate the date and weekending date from these values.

I tried the following but it gives me an incorrect result for the derived date as '2022-08-05 00:00:00'

select to_date(2020||03||20,'YYYYMMDD')

Even tried below but results in a string without leading zeros for month and day

select  (cast (2020 as varchar)+cast (03 as varchar(2))+cast (02 as varchar(2)))

Result for above is : 202032

The problem is that you have numbers -- so leading zeros are missing. You can try:

select to_date('2020'||'03'||'20', 'YYYYMMDD')

Or, if these have to be numbers:

select to_date( (2020 * 10000 + 03 * 100 + 20)::text, 'YYYYMMDD')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM