473,748 Members | 10,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

changing the date_format

83 New Member
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_for mat( '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 7388
ronverdonk
4,258 Recognized Expert Specialist
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 New Member
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,da te_format(curda te ,'%d%m%y') from mytable;
+-------+-------------+-------------------------------+
| name | curdate | date_format(cur date,'%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 Recognized Expert Specialist
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
3081
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 BY time asc and I am getting this error message: MySQL Error number: 1064: You have an error in your SQL syntax near 'ORDER BY time asc' at line 2 I added the "as time" in hopes it wasn't seeing the 'DATE_FORMAT()'field as the time field.
2
2875
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
1937
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 datetime), '%m/%Y') from yo where id = 1" but the data returns incorrectly. For example, the id 1 the time is '28-4-2004-4:11' once I ranthe query, the return data is 04/2028. Looks like MySQL treated 28 as the year. What can I do to make it...
18
2206
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 experiences of changing light bulbs and how the light bulb could have been changed differently
1
1880
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 give the error. If we change the %b to %m ,its worked as both local and web also .but i want the date in format of 06-feb-2007. What can i do for this .Please any one help to do that in web. Thanks in Advance Sang
3
2527
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 as of php 5.2) but I can't get it to work... $date = "2007-06-22 00:00:00"; //I also tried $date = "2007-06-22"; but that didn't work either //I also tried adding strtotime($date); but that didn't help! $month = date_format($date , 'F');
16
2408
by: laverdir | last post by:
<? $query = "SELECT " . $this->tabela3 . ".id, " . $this->tabela3 . ".naziv, " . $this->tabela3 . ".spisatelj, " . $this->tabela3 . ".najava, " . " DATE_FORMAT(" . $this->tabela3 . ".vrijeme_stavljanja, '%e. %c. %Y. %k:%i') FROM " . $this->tabela3 . ", " . $this->tabela2 . " AS xref WHERE " . $this->tabela3 . ".id=xref.spis_id AND xref.vrsta_id=" . $this->DB->quote($vrsta) . " ORDER BY " . $this->tabela3 . ".vrijeme_stavljanja DESC"; ?>
2
3008
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 get rid of the error: SELECT `email`, `raum`, DATE_FORMAT('date',`%c %d`) as date FROM `logger`;
2
1816
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 date_format(). I know that this is built in with PHP 5 but I need to know how to fix it without getting another error message saying that my cookies are disabled. Can anyone please help me?
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.