473,729 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to display date in DD-MM-YYYY format?

157 New Member
Helo,

I have a calendar on my webpage on which the date format is 'DD-MM-YYYY'; user selects a date and it has to be stored in the same format in the backend; but I checked in MySQL there is 'Date' which has the format 'YYYY-MM-DD'.

Is there any way I can store the date in the 'DD-MM-YYYY' or just 'DD-MM-YY' format?
Feb 15 '07 #1
9 70678
ronverdonk
4,258 Recognized Expert Specialist
Make it a VARCHAR(10) or a CHAR(10) field and store it in your format.

Ronald :cool:
Feb 16 '07 #2
abctech
157 New Member
Make it a VARCHAR(10) or a CHAR(10) field and store it in your format.

Ronald :cool:
Thank you,

Actually I need to sort this date coumn and fire queries like select the records between date so and so or select all records for month of Jan etc etc..if I make it as Varchar or Char instead of Date will I still be able to do this? Please guide.
Feb 16 '07 #3
ronverdonk
4,258 Recognized Expert Specialist
No, all date calculations are done using the YYYY-MM-DD format (MySQL DATE format).

I would advise you to leave the DATE format in the db as it is, so you can do calculations, searches etc. Only re-format the date to your required format when displaying it to the user using the DATE_FORMAT MySQL command:
Expand|Select|Wrap|Line Numbers
  1. DATE_FORMAT(your_date, "%d-%e-%Y")
Ronald :cool:
Feb 16 '07 #4
abctech
157 New Member
No, all date calculations are done using the YYYY-MM-DD format (MySQL DATE format).

I would advise you to leave the DATE format in the db as it is, so you can do calculations, searches etc. Only re-format the date to your required format when displaying it to the user using the DATE_FORMAT MySQL command:
Expand|Select|Wrap|Line Numbers
  1. DATE_FORMAT(your_date, "%d-%e-%Y")
Ronald :cool:
Thanks for your suggestion, it should solve my difficulty except for one problem, the Calendar that I'm using(here is the link for it ) has only limited Date-formats, currently I'm using the DD-MM-YYYY format and when I try to save the date in this format it is incorrectly saved, for eg. if I try to save 17-2-2007 it gets saved in the backend 'DATE' column as 2012-02-20, can anything be done through MySQl to avoid this?

I really need the user to choose a Date in the DD-MM-YYYY format only.
Feb 16 '07 #5
ronverdonk
4,258 Recognized Expert Specialist
To store your DD_MM-YYYY date, use the MySQL STR_TO_DATE() function. Example:
Expand|Select|Wrap|Line Numbers
  1. STR_TO_DATE('31/07/2006', '%d/%m/%Y');
returns 2006-07-31.

See the MySQL Date and Time functions

Ronald :cool:
Feb 16 '07 #6
abctech
157 New Member
To store your DD_MM-YYYY date, use the MySQL STR_TO_DATE() function. Example:
Expand|Select|Wrap|Line Numbers
  1. STR_TO_DATE('31/07/2006', '%d/%m/%Y');
returns 2006-07-31.

See the MySQL Date and Time functions

Ronald :cool:
I tried the above query but I get the message "You have an error in your SQL syntax". I am using MySQL version 4.0.16 and I searched the entire manual on my comp for the STR_TO_DATE() function, couldn't locate it, does this function exist in the previous versions or could there be some other problem?
Feb 17 '07 #7
ronverdonk
4,258 Recognized Expert Specialist
Firstly: what I showed was not a query. And of course you cannot execute it. It showed the way you can use the STR_TO_DATE function. In order to use it proper you must put it in an SQL command like SELECT, UPDATE, etc.

Secondly: I cannot imagine that you cannot find that function. When you just follow the link I showed, you will be linked to the date and time functions chapter in the MySQL manual. Within that chapter you can search for the function you want to find.

Ronald :cool:
Feb 17 '07 #8
abctech
157 New Member
Firstly: what I showed was not a query. And of course you cannot execute it. It showed the way you can use the STR_TO_DATE function. In order to use it proper you must put it in an SQL command like SELECT, UPDATE, etc.

Secondly: I cannot imagine that you cannot find that function. When you just follow the link I showed, you will be linked to the date and time functions chapter in the MySQL manual. Within that chapter you can search for the function you want to find.

Ronald :cool:
Yes I did use the function in a query(SELECT) and I was getting a 'syntax-error'. I also visited the page the link for which you'd provided and read the STR_TO_DATE() function there but after trying to use it I was getting an error. I searched for the same in the MySQL manual on my computer, couldn't find it anywhere. I have DATE_FORMAT(), TIME_FORMAT(), MAKEDATE(), NOW(), CAST() etc etc but no STR_TO_DATE() :(.
I really dont know why that is, perhaps my MySQL version doesn't have this function hence I'm getting the error.

Please guide if there is some other way. For the time being I'm trying to convert the DD-MM-YYYY Date into YYYY-MM-DD Date through the front-end(Java) itself and then save it in the backend.
Feb 17 '07 #9
abctech
157 New Member
Helo again,

I got it resolved now, tried the program using MySQl 5.0, the STR_TO_DATE() works there.Thanks for all your help, much appreciated!
Feb 17 '07 #10

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

Similar topics

34
2096
by: kroger | last post by:
Hi. I am at a loss to decipher why the javascript on my web page: http://www.psych.nmsu.edu/~jkroger/lab/index.html does not display the date correctly in Firefox. Instead of "2005" for the year, it displays "105" ... however, in IE Explorer, it looks fine. Thanks for any help, Jim
6
9342
by: Franz | last post by:
Hy all, I have a problem with a date in javascript on firefox Browser. I use this javascript method: var dataNow=new Date(); var dd=dataNow.getDate(); var mm=dataNow.getMonth()+1; var yy=dataNow.getYear();
2
1648
by: Kiran | last post by:
Hi, Is it possible to display date in different languages depending upon the culture. Thanks Kiran
7
3372
by: mpmason14 | last post by:
i am trying to get a report to show the dates for a specified starting date entered on a form (the report is based on the form). the report is a timesheet/payroll setup that goes for two weeks. for example, the user enters the starting date as 07/03/2006 and i want the report to display each day for the following two weeks (Mon-Sun). any ideas? if you need clarification i will provide as necessary. thanks in advance
0
2236
by: keithsimpson3973 | last post by:
Does anyone know if it is possible to display the value of a date picker control on a vb6 form that the user selected on an access report? I am using vb6 to display a report selection and it has a date picker combo for the start date and another for the stop date. I would like to display those 2 dates on the header of the access report to show the date ranges that were selected.... Thank you all in advance
2
1781
sumaiya
by: sumaiya | last post by:
how can i display date subtraction
0
1728
by: keithsimpson3973 | last post by:
Does anyone know if it is possible to display the value of a date picker control on a vb6 form that the user selected on an access report? I am using vb6 to display a report selection and it has a date picker combo for the start date and another for the stop date. I would like to display those 2 dates on the header of the access report I am opening from Visual Basic 6. Thanks for any help anyone can give....
2
2118
by: Vbbeginner07 | last post by:
How to display current date in a datepicker where once we have loaded the datepicker onto form it shows current date,but after some days it shows only the date when it was loaded onto the form,please ny suggestions to get the current date always inspite of the date loaded being shown!!!
1
1539
by: jackiefm | last post by:
I need to display date ranges for missing data in a query in the following manner: 1/1/08-1/15/08, 126/08, 1/28/08-2/5/08, etc. as opposed to 1/1/08 1/2/08 1/3/08 etc.
5
3336
by: jamesnkk | last post by:
Hi, I am wondering is it possible to display current date and time on status bar or display on a customize toolbar ?
0
8936
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8768
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,...
1
9226
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
9166
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
8170
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
6722
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
4799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3248
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2705
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.