change the format of the date - mysql

I have default date from database like '01/02/2015'.
How can I output date in '1/2/2015' format?

You can use the DATE_FORMAT function with the formating string as %c/%e/%Y to get the format you want.
DATE_FORMAT(CURDATE(),'%c/%e/%Y')
Here are more formats and information about them.

select DATE_FORMAT(YOUR_DATE,'%e/%c/%Y') from your_table
references : w3schools

Related

Converting Date to String and then to Date again in mysql .Combining 2 functions in mysql

have column which is of type date having default format as YYYY-MM-DD. I want to get date in format DD-MM-YYYY but as date type only. I would like to know how is it possible? I am combining 2 functions together as shown below but i am not getting the desired result
STR_TO_DATE(DATE_FORMAT(emp.doj, '%d-%m-%y'),'%d-%m-%y') as doj
Please dont close this questions as its a different one not asked before thanks!!!
DATE_FORMAT(emp.doj,'%d-%m-%Y') as doj
You have not need to use STR_TO_DATE. use only DATE_FORMAT. It should be work.

How do i format different formats of date in Mysql

I want to format
1/2/55
05/06/82
9-15-58
2/12/65
02-17-1967
2007-06-12
04/29/197
dates in to MM/DD/YYYY. these are in varchar now. need to format and convert in to date. Any help please
You use mysql DATE_FORMAT() method.
Link:
https://www.w3schools.com/sql/func_mysql_date_format.asp
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

How can we change date format in MySQL

I want to change date format in mysql.I tried this code
DATE_FORMAT(STR_TO_DATE(mydate, '%d.%m.%y'), '%Y-%m-%d')
But its not hep me.
My date comes from as string like this:
DD-MM-YYYY
I want to change it to this:
YYYY-MM-DD
How can I achive this with mysql?
Thanks
Would:
STR_TO_DATE(mydate, '%y.%m.%d')
work then because when your are creating the date from the string you are implicitly giving it a format. Then just call it in a different format.
SELECT str_to_date(table_column_name,'%d-%m-%Y') FROM `table_name`

how do I convert date type to hh:mm in mysql?

I got in my table two types:
hour_Event in type date
date_Event in type datetime
I would like hour_Event to be formatted to hh:mm
and date_Event to be dd/mm/yyyy
I use PHPMyAdmin and im new with MySQL so I dont know how to change the format and for what.
How do I do it?
**DATE_FORMAT(hour_Event,'%h:%i')** will give you hour_Event in hh:mm
and
**DATE_FORMAT(date_Event,'%d/%m/%Y')** will give you date_Event in dd/mm/yyyy
You could change the format using php before you insert data or after retrieving themfrom your database according to your needs.You could use DateTime / strtotime() & date(). In most cases a single timestamp field in your table is enough for an event.
Have a look here:
Convert one date format into another in PHP
Also you could format your field according to your needs with mysql for example:
DATE_FORMAT(tables.field, '%d-%m-%Y %H:%i:%s') AS 'new_name'
Have a look about it here:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format

How to convert yyyy/mm/dd to dd/mm/yyyy?

I would like to convert yyyy/mm/dd to dd/mm/yyyy format.So, I am using strtotime() function.but when I get zero date like(0000/00/00) from mysql. It will be showing wrong date like(01-01-1970).
I need exact string like 0000/00/00 to 00/00/0000. any other function are there?
Try MySQL's DATE_FORMAT() function
SELECT DATE_FORMAT(dateColumn,'%d/%m/%Y') AS dateColumn FROM table...
Try to use strftime
strftime("%d-%b-%Y", strtotime($value['your_date']));