Is there a way to convert date of type 'dd-mmm-yy' to 'yyyy-mm-dd' format in big query
eg: 01-mar-15 to 2015-03-01
Thanks!.
SELECT PARSE_DATE("%m-%b-%y", "01-mar-15") as parsed;
Output:
Row parsed
1 2015-03-01
Related
I have data with dates as:
ID Date1 Date2
1 1.929e+12 1.929e+12
2 1.917e+12 1.901e+12
3 1.922e+12 .
Based on other dates in the dataset, they should be in yyyy-mm-dd hh:mm:ss format.
Open to solutions within Stata or using different software.
Your values are already date-times so all you need to do is assign a date format starting %tc. Here are examples using display on one of your scalar values:
. di %tc 1.929e+12
15feb2021 09:20:00
. di %tcCCyy-NN-dd_HH:MM:SS 1.929e+12
2021-02-15 09:20:00
See
help datetime_display_formats
help format
for how to select a datetime format and assign it to a variable.
For example,
format Date1 %tcCCyy-NN-dd_HH:MM:SS
I want to convert below string to only date column. the column has both time and date stored as string
String
2021-01-01 12:43:58 ==> 2021-01-01
You achieve what you want with this query:
SELECT
cast(date_parse(column, '%Y-%m-%d') as date)
FROM
table
You can use date_format with date_parse or cast as date to achieve this:
SELECT date_format(date_parse('2021-01-01 12:43:58', '%Y-%m-%d %h:%i:%s'),'%Y-%m-%d')
will give 2021-01-01
Just replace the timestamp with column name
SELECT date_format(date_parse(<timestamp_column>, '%Y-%m-%d %h:%i:%s'),'%Y-%m-%d')
Now using cast as shown below
SELECT cast(date_parse('2021-01-01 12:43:58', '%Y-%m-%d %h:%i:%s') as date)
similarly replace timestamp with column name
For what is worth, here's a solution without casting back and forth from string to date:
select substr(column,1,10) from mytable
I have an excel file having a column with Text format values like Jan-18, Dec-19, Feb-20. I want to convert it to a date format but when I am trying to make this column a date format it printing 1/18/2021, 12/19/2021,2/20/2021. Basically its considering Jan as month(1), 18 as Date, & making all year as 2021 deafult.
Can someone help?
Original(text) After Date conversion Desired format
Jan-18 1/18/2021 01/01/2018
Feb-19 2/19/2021 01/02/2019
Mar-20 3/20/2021 01/03/2020
You can try,
DATE(2018, MONTH(convertedDate), 1)
This will convert your converted date to the first day of the relevant month in 2018. This is stored in Power BI as a datetime object. If you want to show that value in dd/MM/yyyy format you can do it by selecting correct Format in the top menu.
If you load in the Original column as text, try this trick:
Desired format = DATEVALUE ( "1-" & [Original] )
Appending the "1-" to the beginning gives it a day of the month and forces it to recognize the last digits as the year.
I faced with the same issue , while changing the format instead of using Date use the last option i.e "Using Locale... " -> in that change the Data Type from Text -> Date, and Locale to English(United Kingdom) -> Hit ok. Earlier Format ,What should be the desired format .This worked for me!
Currently , I have date column in time format ,I want to change it to date time stamp format I.e ( I want the date column to look like 12nov 2020 12:03:45:00 )
Could someone help me on this ?
According to #KurtBremser:
SAS dates are counts of days, SAS datetimes are counts of seconds.
datetime = dhms(date,0,0,0);
will convert a date to a datetime. Or multiply by 86400.
A column showing a time representation hh:mm:ss can be one of three things:
A character column type containing digit characters 0-9 and :
A number column type containing a SAS time value being displayed as hh:mm:ss with the time format TIME8.
A number column type containing a SAS datetime value being displayed as hh:mm:ss with the datetime format TOD.
This sample program demonstrates how different kinds of values can all look the same when viewed.
data have;
v1 = '12:34:56';
v2 = hms(12,34,56);
v3 = dhms(today(),12,34,56);
put v1= / v2= time8. / v3=tod. / v3=datetime18.;
run;
------ LOG ------
v1=12:34:56
v2=12:34:56
v3=12:34:56
v3=25NOV20:12:34:56
Only #3 has enough information in the raw value to be formatted as ddmmmyyy:hh:mm:ss
format myDate datetime18.;
#2 requires computing a new value assuming something about the date part
* supposing myDate contains only time values (00:00:00 to 23:59:59) for today;
myNewDate = dhms(today(),0,0,0) + myDate;
format myNewDate datetime18.;
#1 requires interpretation through INPUT and a date assumption
* supposing myDate contains "hh:mm:ss" for today
myNewDate = dhms(today(),0,0,0) + input(myDate,time8.);
format myNewDate datetime18.;
I have column name as IsGreater.
This column is filled by comparing two fields of dates.
one is today's date and another is date field in text format ex: "12/1/2018 8:00:00 AM" in text format.
I need to compare these two dates and return true or false.
Thanks in advance.
I am trying
IsGreater = IF((FORMAT(TODAY(),"MM/DD/YYYY HH:MM:SS tt"))>
(FORMAT([date],"MM/DD/YYYY HH:MM:SS tt")),true,false)
and
IsGreater = IF((FORMAT(TODAY(),"MM/DD/YYYY HH:MM:SS tt"))>
(FORMAT([date],"MM/DD/YYYY HH:MM:SS tt")),True(),False())
It's not working as assumed.
Need in help.
expected to be true as the date field contains "12/1/2018 8:00:00 AM" which is past.
Just reorder DD and MM:
= IF((FORMAT(TODAY(),"DD/MM/YYYY HH:MM:SS tt"))>
(FORMAT([Date],"DD/MM/YYYY HH:MM:SS tt")),true,false)