Convert Numeric to Date

Converting a numeric value to date time

I have just found the way to do this.

First I have to covert the nvarchar to int then I have to convert it to date time. I have used following code:

Select convert(datetime, (convert (int, [date_column])), 6) as 'convertedDateTime' from mytable

DB2 Convert Number to Date

1) How do I convert the OAORDT field to Date?

Simplest is to use TIMESTAMP_FORMAT :

SELECT DATE(TIMESTAMP_FORMAT(CHAR(OAORDT),'YYYYMMDD'))

2) Being in the UK I need it to be [...] in Date format 21/12/2017 :

SELECT VARCHAR_FORMAT(DATE(TIMESTAMP_FORMAT(CHAR(OAORDT),'YYYYMMDD')),'DD/MM/YYYY')

how to convert numeric only year in Date in R?

You could use round_date, [EDIT] or better floor_date to round to the start of the year(see comment & answer below):

library(lubridate)

df2 <- df %>%
mutate(date2 = dmy(date2)) %>%
mutate(year_internal = round_date(date2,'year')) %>%
mutate(year_out = format(year_internal,'%Y'))

df2 %>% select(date2, name, year_internal, year_out)

date2 name year_internal year_out
1 2000-01-01 A 2000-01-01 2000
2 2000-08-08 B 2001-01-01 2001
3 2001-03-16 C 2001-01-01 2001


Related Topics



Leave a reply



Submit