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?
9 70624
Make it a VARCHAR(10) or a CHAR(10) field and store it in your format.
Ronald :cool:
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.
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: - DATE_FORMAT(your_date, "%d-%e-%Y")
Ronald :cool:
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: - 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.
To store your DD_MM-YYYY date, use the MySQL STR_TO_DATE() function. Example: - STR_TO_DATE('31/07/2006', '%d/%m/%Y');
returns 2006-07-31.
See the MySQL Date and Time functions
Ronald :cool:
To store your DD_MM-YYYY date, use the MySQL STR_TO_DATE() function. Example: - 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?
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:
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.
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!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
by: Kiran |
last post by:
Hi,
Is it possible to display date in different languages depending upon the
culture.
Thanks
Kiran
|
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.
...
|
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...
|
by: sumaiya |
last post by:
how can i display date subtraction
|
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...
|
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...
|
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.
|
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 ?
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |