Im my Mysql db there is a date field called "completed date " ,its data type is datetime. I need to convert into week format. This should be week ending saturday. this week based date should comes in new column also.Please Provide the query
Try
SELECT week("completed date") FROM "myTable";
A brief documentation can be found here
Related
I have this column in MySQL table:
Date
2022-07-13 07:01:20
I want to extract this column to get this (the date and hour only):
2022-07-13 07
Any help is appreciated thanks!
This date column is in the form of timestamp
Apparently timestamp is a string so i can use substring.
To select the date and hour from that format first you have to take the substring using SUBSTRING()
the convert to datetime format using STR_TO_DATE()
you can take the specific date using SELECT CONVERT(date, your_date_time);
then extract the hour to add it in there SELECT HOUR()
you can then convert back to a string or use it that way
I have date in the following format stored in Mailed_Date column
Mon, 09/20/10 01:04 PM
I have used a serde(csv-serde-1.1.2-0.11.0-all.jar) to get this date from a csv file and stored it as a String.
How can i get the time of day, day of week, Month from this date in Hive.
I tried using
select HOUR(Mailed_Date) from final3 limit 5;
but got a NULL as answer.
I think i found the answer to my query:-
select day(from_unixtime(unix_timestamp(substr(Mailed_Date, 6, 14), 'MM/dd/yy hh:mm'), 'yyyy-MM-dd hh:mm')) from final3 limit5
Here first I extract the date and then convert it to the required format which is acceptable by Hive to get the day, month or time from.
Got a hint from the below question:-
Convert mm/dd/yyyy to yyyy-mm-dd in Hive
As i am trying to insert the date 'March16' which is March 2016 in mysql table x with datatype DateTime. But this gives me error incorrect date value.
Please help me . Thank you very much
'March16' is not a correct date format. You need to do STR_TO_DATE() or DATE_FORMAT().
Read more about above two.
If you want to insert only month and date
Mysql doc
Ranges for the month and day specifiers begin with zero due to the
fact that MySQL permits the storing of incomplete dates such as
'2014-00-00'.
This means that to store the year and month only, you
can use a DATE column and put 00 instead of the day. e.g 2013-12-00.
Given - Due to some bad design (legacy), one of the columns in my table(named delivery_time) has 'delivery time' stored as string in the format 'hh:mm PM'. I have another column (named delivery_date) with 'date' data type with format yyyy-mm-dd.
What to do - Using the information in these two columns I need to find date (day and time) in unix timestamp..
I was able to convert delivery_date to unix timestamp using the following function -
unix_timestamp(cast(delivery_date as date))
Can anyone suggest how to take care of delivery_time column?
Not verified but i guess this will work for you
SELECT
UNIX_TIMESTAMP(CONCAT(delivery_date, ' ',
STR_TO_DATE(delivery_time,'%h:%i %p)) AS
my_unix_timestamp
how do i search dates using mysql.
Database fields are like this:
date
Monday, 21 December 2009 11:54:16
timeurl
1261376656
I have date text field: '21/12/2009'
how do i search date in the database. 'date' field type is varchar and timeurl type is timestamp
thanks
If you are asking about the date format you need to enter in your query it's:
For queries on a DATE column you should enter dates with format 'yyyy-MM-dd'.
For queries on a TIMESTAMP or DATETIME columns you should enter dates with format 'yyyy-MM-dd HH:mm:ss'
MySql is very flexible on this - you can actually use many other formats for insertion and querying as described here.