473,811 Members | 3,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Current date as the default value of a date field

20 New Member
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 4929
sumaabey
29 New Member
echo $d=date("d/m/Y");
Jun 26 '07 #2
sharmilah
20 New Member
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,99 9) in the database itself so that all numbers input get this format.

Thanks again
Jun 26 '07 #3
sumaabey
29 New Member
select date_format(tes t_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 Recognized Expert Expert
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,99 9) 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 Recognized Expert Specialist
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,99 9) 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 Recognized Expert Expert
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 Recognized Expert Expert
The one exception (I just discovered this today) is that you can use CURRENT_TIMESTA MP 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
4308
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 could retrieve all the records for a specific date if I hard-code the date into the query, but not if I want to prompt the user. Has anybody else experienced this? Does anybody have any suggestions?
2
3253
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 generated (or before), assign the current date to the field in the main table the query data source is based on. Is this even possible? If so, how could I do it? Here is the code that works so far:
11
10626
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 in Date loaned-field? How do I add 4 weeks to date loaned and can I do it in INSERT INTO-sentence?
7
31846
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 current date. If not, I'd like to display the error message to ValidationSummary. It seems to make sense to me to use CompareValidator but the problem is put the current date into CompareValidator. So, I created a hidden text field in my aspx. ...
5
2157
by: tshad | last post by:
I have the following code: *************************************************************************** Dim CommandText as String = "INSERT INTO ftsolutions.dbo.position (client,dateposted) VALUES ( @client,@dateposted)" Dim objCmd as New SqlCommand(CommandText,objConn) with objCmd.Parameters .Add("@client",SqlDbType.Char,50).value = "the companies next test" .Add("@dateposted",SqlDbType.datetime).value = dateposted.text
1
1998
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 it. How can he do so? (He doesn't want to bother registering with TSDN, so I agreed to post the question.) If he sets it as a current date field, it doesn't allow overwrite. But it seems as though the default value has to be a hard-coded date/time...
1
4344
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 logic for a date field. i.e. theValue.defaultvalue = "#" & theValue.value & "#" I can't get this to work for some reason and I can't figure out why. Can anyone out there help? Thanks Repeat value of previous record field into current...
3
6294
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 NullValue in my datagridview... Everything works great, with a table-row added manually to the database, without setting any value to the second date-field. Both the datagridview and the datetimepicker displays correctly the DBNull value..
4
3033
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 VB code, so please if at all that can be avoided otherwise please be a bit thourough on the codes including the declaration bit. Thanks
0
9605
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
10393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10136
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
9208
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...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
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
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.