| | |
storing date mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
actually i have a table user_register_mobile in mysql. [Email,MobileNumber,Registratinon_date... are some filed there.] in this table i have a field registration_date.i want to keep date so that i know when user register to our site.
i read about timestamp,some date,time functon of php,but didn't get it. but if u want explain it i am ready to learn
i read about timestamp,some date,time functon of php,but didn't get it. but if u want explain it i am ready to learn
In your mysql table you should set the type to 'timestamp' and then set the default to 'CURRENT TIMESTAMP'.
It doesnt really need to be explained. All that is doing is getting the date and time from the server and sticking it in a field. Just remember not to update it when you update the table, that way it will stay the day the user registrated.
Hope this helps, if you need anything else or i've miss understood dont hesitate to ask.
Also, if you need more info on timestamp and storing the date, i suggest you consult the manual. It contains some really usefull stuff.
It doesnt really need to be explained. All that is doing is getting the date and time from the server and sticking it in a field. Just remember not to update it when you update the table, that way it will stay the day the user registrated.
Hope this helps, if you need anything else or i've miss understood dont hesitate to ask.
Also, if you need more info on timestamp and storing the date, i suggest you consult the manual. It contains some really usefull stuff.
•
•
Join Date: Jul 2008
Posts: 148
Reputation:
Solved Threads: 25
Store a UNIX Timestamp in that mysql column.
$iCurrentTime would result in an integer like: 1236884436
Which is the number of seconds since the Unix Epoch.
You can pass that integer into the php date() function and format it any way you want, and you can also calculate against it simply using basic math.
The only drawback is that it can not store dates after 01/2038 because it will exceed the size of a 32bit integer or Before 01/1970. By 2038 I imagine 64bit hardware or greater will pretty much be the norm.
php Syntax (Toggle Plain Text)
<?php $iCurrentTime = time();
$iCurrentTime would result in an integer like: 1236884436
Which is the number of seconds since the Unix Epoch.
You can pass that integer into the php date() function and format it any way you want, and you can also calculate against it simply using basic math.
The only drawback is that it can not store dates after 01/2038 because it will exceed the size of a 32bit integer or Before 01/1970. By 2038 I imagine 64bit hardware or greater will pretty much be the norm.
If you're question/problem is solved don't forget to mark the thread as Solved!
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
•
•
Join Date: Jul 2008
Posts: 148
Reputation:
Solved Threads: 25
That is because your column type is set to datetime or timestamp not certain which one actually produces that as I don't use the mysql datetime or timestamp data type.
To store a unix timestamp you just need an INT(10)
To store a unix timestamp you just need an INT(10)
If you're question/problem is solved don't forget to mark the thread as Solved!
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
![]() |
Similar Threads
- PHP MySQL date question. (PHP)
- updating multiple columns in single MySQL table (PHP)
- Displaying date from mysql (PHP)
- Events / News Section - PHP/MySQL Question (PHP)
- Help with birthday MySQL Script (MySQL)
- Inserting date in format DD-MM-YYYY in MySQL (MySQL)
- HTML mail subscriiption error (PHP)
Other Threads in the PHP Forum
- Previous Thread: Mysql result in columns
- Next Thread: PHP unlink ERROR !!!
| Thread Tools | Search this Thread |
apache api array basic beginner binary broken cakephp checkbox class cms code computing confirm cron curl customizableitems database date delete display dynamic echo email error external file files filter folder form forms forum function functions gc_maxlifetime google headmethod host href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction memmory memory menu mlm multiple mysql navigation neutrality oop parsing paypal pdf php problem query question radio random recursion remote root script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validator variable video web xml youtube






