Converting yyyy-mm-dd date format into yyyymmdd in R - r

I see there are many solutions for converting yyyymmdd to yyyy-mm-dd format, but it is hard to find a code that converts yyyy-mm-dd to yyyymmdd.
What would be the best way to convert a date format yyyy-mm-dd to yyyymmdd?
Thanks in advance for all your help!

try this :
format(as.Date("1970-01-01"), "%Y%m%d")

Related

Convert date to other format other than YYYY-MM-DD

I need to convert input date coming in format YYYY-MM-DD. First I convert it into char by following:
TO_CHAR(<date_column>,'YY/MM/DD')
then try to convert it into date for this format:
to_date((TO_CHAR(<date_column>,'YY/MM/DD')),'YY/MM/DD')
As to_date always converts to default date type of YYYY-MM-DD. What other way can I use to convert this into other format. I am using Informatica Powercenter, so I can not find other function other than TO_DATE.
I think we are ignoring basics - to_date() converts to a date format. Now it can be displayed in dd/mm/yyyy depending on setup in your DB client or if you are dumping in a file probably YYYY-MM-DD. And on a date filed you cfan use TO_CHAR o convert it to any format.
So, if your input is a string and is in 'YY/MM/DD' then use TO_CHAR(TO_DATE(imp_yymmdd,'YY/MM/DD'),'DD/MM/YYYY') - output will be a string of your desired format i.e. DD/MM/YYYY.
If your input is a date then use TO_CHAR(imp_date,'DD/MM/YYYY') - output will be a string of your desired format.
Date datatype has no format. You can format a string representing a date.
Assuming your input is date, just use TO_CHAR(yourdate, 'desiredformat').
If your input is a string, you first need to convert it to date then back to string again, with the desired format applied. So:
TO_CHAR(TO_DATE(yourstring, "format-it-comes-in"), "desired-format")
Which in your case would be:
TO_CHAR(TO_DATE(yourstring, "YYYY-MM-DD"), "YY/MM/DD")

Date time format with TZ specfied with datetime in R( ISO 8601 )

I need to get current time in R in this particular format:
2014-01-07T14:57:55+05:30
Sys.time() seems to return in a different format than this. How do I exactly get this ?
Link to the format : https://en.wikipedia.org/wiki/ISO_8601
The function for converting/formatting a time string is as.POSIXct or as.POSIXlt. The documentation for these points to the docs for strptime for format symbols. This reference indicates %F is the correct symbol for ISO-8601 however, implementing that results in a format different from what you suggest.
> as.POSIXct(Sys.time(),format="%F")
[1] "2016-10-02 18:57:58 EDT"
I suspect looking at strptime you will find the combination necessary to output the exact format you need.
Is this what your looking for?
format(Sys.time(), format="%Y-%m-%dT%H:%M:%S+01:00")
format(Sys.time(), format="%Y-%m-%dT%H:%M:%S%z")
The meaning of the letters you find a the documentation of strptime() function

UNIX Datetime format

I have a scenario where there is a unix time format 2014-01-09-03-26-09_5403.
I want to know what time format is this. When I am trying the below format:
start_time=$(date '+%Y-%m-%d-%H-%M-%S')
It is giving me only 2014-01-09-03-26-09.
Can you please help me in achieving this time format?

How can I convert datetime to date format in SQLite?

I want to show a date in DD-MM-YYYY format in a datagrid. By default, SQLite stores the data in date-time format. So how can I convert date-time format to date format in flex by using SQLite?
You can use strftime, from Date And Time Functions.
Example:
SELECT strftime('%d-%m-%Y', 'now')
output:
10-06-2010
Look up Java until Date. It has methods to convert and is supported in SQLite. However it is mostly deprecated and replaced with Calender.

How to covert mm/dd/yyyy to dd/mm/yyyy

I have a textbox in which date is in format mm/dd/yyyy. I want to convert it from mm/dd/yyyy to dd/mm/yyyy in asp.net with vb to a DateTime variable.
DateTime.ParseExact("12/21/2008", "MM/dd/yyyy", CultureInfo.InvariantCulture).ToString("dd'/'MM'/'yyyy")
Update: Given that you want to have a DateTime in the end, you can just parse the original format:
DateTime.ParseExact("12/21/2008", "MM/dd/yyyy", CultureInfo.InvariantCulture)
The date formats are of use only when presenting the date as a string (internally the date does not have a format; it's just a number). If you want to store it in a DateTime all you need to bother about is to interpret the input correctly.
If you are dealing with a DateTime object you convert can like this:
yourDateTime.ToString("dd/MM/yyyy"))

Resources