/    Sign up×
Community /Pin to ProfileBookmark

inserting ‘today’s date’ in MySQL

This is a simple question, but I haven’t had much luck finding the solution.

I have a form where a user will enterd his name and address and click on Submit. I’m using PHP to capture this info and enter in a MySQL table. In the table, I also have a field of type ‘date’. WHen I insert the name and address, I also want to enter the current date. I’m using date() in my ‘insert into table’ command, but it doesn’t seem to work. What is the correct syntax to enter today’s date! Thank you!

DL

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@aussie_girlNov 06.2006 — This is a simple question, but I haven't had much luck finding the solution.

I have a form where a user will enterd his name and address and click on Submit. I'm using PHP to capture this info and enter in a MySQL table. In the table, I also have a field of type 'date'. WHen I insert the name and address, I also want to enter the current date. I'm using date() in my 'insert into table' command, but it doesn't seem to work. What is the correct syntax to enter today's date! Thank you!

DL[/QUOTE]


I use NOW()
Copy linkTweet thisAlerts:
@so_is_thisNov 06.2006 — What data type did you use? I have a case where I used the DATETIME data type and I store the current date and time as follows:
[code=php]
$sql = "Update OrderHeaders Set
ord_stat = 'Open',
ord_stmp = NOW()
Where ord_numb = {$ord_numb}
Limit 1;";[/code]
Copy linkTweet thisAlerts:
@theRamonesNov 06.2006 — input date() format in MySql : date("Y-m-d"), wish u luck ?
Copy linkTweet thisAlerts:
@so_is_thisNov 06.2006 — There is also [B]CURDATE()[/B] which you can use for just a date.
Copy linkTweet thisAlerts:
@netbuddyNov 06.2006 — This would be better done within MySQL itself, the internal date format will be in the format that is easily read by the server system, you wouldnt need to go to lengthy processes to ensure that you have formatted the date correctly.
Copy linkTweet thisAlerts:
@so_is_thisNov 06.2006 — This would be better done within MySQL itself...[/QUOTE]
Both NOW() and CURDATE() are intrinsic MySQL functions.
Copy linkTweet thisAlerts:
@datalineauthorNov 07.2006 — Thanks to all (aussie girl, so_is_this, theRamones, netbuddy) for your replies! I've tried now() and curdate(), and both work the way I want it to!

I've done some reading about the 'date' type, but for some reason I find it hard to understand. May be I should spend more time on it. Again, thanx to all for the help!

DL
×

Success!

Help @dataline spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...