473,412 Members | 3,860 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,412 software developers and data experts.

Current date as the default value of a date field

Hi all

It's me again. I now want to specify the current date in the format '26/06/2007' ie date/month/year as the default value in my mysql database. Which implies that by default the value of my date field in the database should be the current date. How can I do this in the Mysql database itself, so that each time my application is called the current date appears by default.

Thanks in advance for your replies
Jun 26 '07 #1
7 4899
echo $d=date("d/m/Y");
Jun 26 '07 #2
Is it possible to specify the date format (e.g 26/06/2007) in the mysql database itself instead of converting it via php.

Another question : I want also to specify the format of a numeric field (999,999,999,999) in the database itself so that all numbers input get this format.

Thanks again
Jun 26 '07 #3
select date_format(test_date,'%d/%m/%Y') as test_date from test_table

this query will display the format that you need

do you want this?
Jun 26 '07 #4
pbmods
5,821 Expert 4TB
Heya, sharmilah.

Is it possible to specify the date format (e.g 26/06/2007) in the mysql database itself instead of converting it via php.
Yes. But it hasn't been implemented yet.

Expand|Select|Wrap|Line Numbers
  1. SHOW VARIABLES LIKE 'date%';
Another question : I want also to specify the format of a numeric field (999,999,999,999) in the database itself so that all numbers input get this format.
Can't specify a format for numeric types, but you can FORMAT() them.
Jun 26 '07 #5
Motoma
3,237 Expert 2GB
Is it possible to specify the date format (e.g 26/06/2007) in the mysql database itself instead of converting it via php.

Another question : I want also to specify the format of a numeric field (999,999,999,999) in the database itself so that all numbers input get this format.

Thanks again

To your first question, change your insert statement to use NOW() as the value of the date.
Jun 26 '07 #6
Atli
5,058 Expert 4TB
It is not possible (as far as I can tell) to use functions as a default values for fields in MySQl, so you will have to include this in your INSERT statement.
You can use the NOW() function in the Insert statement, which will insert the current date into the field.

If you don't like that you could create a procedure to do this, but thats a little much trouble for a simple thing like this, in my opinion.
Jun 27 '07 #7
pbmods
5,821 Expert 4TB
The one exception (I just discovered this today) is that you can use CURRENT_TIMESTAMP as the default value for the timestamp type.

No, you can't use CURRENT_DATE as the default value for a date type. I don't know why.

http://dev.mysql.com/doc/refman/5.0/...-defaults.html
Jun 27 '07 #8

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

Similar topics

5
by: Javier | last post by:
I have a field type Date/Time that automatically defaults to Now(). I'm having a problem writing a query that will retrieve all the records for a specific date the user to enters when prompted. I...
2
by: William Wisnieski | last post by:
Hi Everyone, Access 2000 I have some code behind a button that performs a word merge with a query data source. The merge works fine. But what I'd like to do somehow is after the merge is...
11
by: Miikka Hamalainen | last post by:
Hi All, I'm making library db using SQL. I have date when book has been loaned (Date loaned) and date to return the book (Return date), which is 4 weeks. How can I get current date to show...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
5
by: tshad | last post by:
I have the following code: *************************************************************************** Dim CommandText as String = "INSERT INTO ftsolutions.dbo.position (client,dateposted) VALUES...
1
by: Killer42 | last post by:
Hi all. I have a question from a colleague. He is creating a form in Word2003, which has a date field on it. He wants to set the default value to the current date, but allow the user to overwrite...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
3
by: Finn Stampe Mikkelsen | last post by:
Hi I have defined a table in my database, with 2 date-fields. I have set a default value to DBNull. I have integrated a nullable datetimepicker control to my project and set the apropriate...
4
by: Tang | last post by:
Hi, could anybody help me with this please I want to add a date stamp in a table, it should automaticlly updated when another field in the same table is selected as "Yes". I am not very good at...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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
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...
0
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,...
0
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...

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.