473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

changing the date_format

83
Hai

I want to change the date format at the time of inserting the record.
i done it but one error in the insertion.

The query is

insert into mytable(update) values(date_format( '2006-10-09','%d%m%y');
Query OK
but in the out put it will be in the form of '2009-10-06' ie in the date field 20 is added

please help any one

Thanks in advance
Sang
Oct 9 '06 #1
3 7361
ronverdonk
4,258 Expert 4TB
If the column containing the date has the MySQL DATE data type, it will store it as YYYY-MM-DD. See the following from the MySQL documentation at Overview of Date and Time types

DATE

A date. The supported range is '1000-01-01' to '9999-12-31'. MySQL displays DATE values in 'YYYY-MM-DD' format, but allows you to assign values to DATE columns using either strings or numbers.
In your case MySQL accepts '06-10-09' as year 2006, month 10 and day 9.
You can either use the standard date type and use date_format in the display of the date, or make the field a CHAR field but then it will be difficult to do arithmetic on its value. I would choose the first solution.

Ronald :cool:
Oct 9 '06 #2
sang
83
Thank you very much for your reply

now i am changing my format as string.

i am insert date like this '20-oct-2006' using data type varchar.

at the time of select i want to change the date format like this '20-10-2006'

i will try with this qurey but not working

that is

select name,curdate,date_format(curdate ,'%d%m%y') from mytable;
+-------+-------------+-------------------------------+
| name | curdate | date_format(curdate,'%d%m%y') |
+-------+-------------+-------------------------------+
| mysql | 20-oct-2006 | |
+-------+-------------+-------------------------------+
out put is like this

please give me the solution
Thanks
Sang
Oct 9 '06 #3
ronverdonk
4,258 Expert 4TB
I assume you have to use PHP to do that. A much better solution would be if you inserted your data as (I am jusing NOW for the date here) e.g.
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO table_name (name, cur_date) VALUES('John', NOW())
and select back with
Expand|Select|Wrap|Line Numbers
  1. SELECT name, DATE_FORMAT(cur_date, '%d-%m-%y') as cur_date FROM table_name
That nwill give you the required 'day-month-year' format.
One of the main reasons to still use the DATE type for cur_date is that you can, when the need arises, do arithmetic on the dates.

Ronald :cool:
Oct 9 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rick | last post by:
I have been trying to run this MySQL query using PHP: SELECT id, trans_type, remote_addr, DATE_FORMAT(time, '%M %e, %Y %r') as time FROM transactions WHERE client_id = " . $client_id . " ORDER...
2
by: Johan den Boer | last post by:
Hi, What is wrong with this code ? SELECT DATE_FORMAT( myfield, GET_FORMAT( TIMESTAMP, 'EUR' ) ) FROM T_TABLE; regards Johan
0
by: Jimmy | last post by:
Hi, I'm new to MySQL and I have qustion regarding to CAST and Date_Format functions. I'm trying to convert a column 'Time' varchar(50) to datetime datatype by "select date_format(cast(time as...
18
by: Chris Hills | last post by:
A lesson in Posting How many C.L.C group posters does it take to change a C light bulb? 1 to change the light bulb and to post that the light bulb has been changed 14 to share similar...
1
by: sang | last post by:
Hi In my table the date format is changed to 06-feb-2007.The query i execute is select date_format(col.name,"%e-%b-%Y") from tablename; This is worked well in local but in the web it will...
3
by: adamalton | last post by:
I am trying to take a date in the format "YYYY-MM-DD" and get from it the month as a word (e.g. July) and the day as a 2 digit number (e.g. 24). I am trying to use the date_format function, (new...
16
by: laverdir | last post by:
<? $query = "SELECT " . $this->tabela3 . ".id, " . $this->tabela3 . ".naziv, " . $this->tabela3 . ".spisatelj, " . $this->tabela3 . ".najava, " . " DATE_FORMAT(" . $this->tabela3 ....
2
by: docscsi | last post by:
Dear all I'm quite new to mysql. My aim is to select a date format field by returning only the month and day number of it (e.g. date = 11 12). I got this statement and I could not get out how to...
2
by: ann86 | last post by:
Hello, I am a newbie to PHP and I am working on a site that was created by someone else. The server was updated yesterday so now I am getting the error Fatal error: Cannot redeclare...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.