| | |
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 |
ajax apache api array beginner beneath binary broken cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include incode insert integration ip javascript joomla limit link login mail match menu method mlm mod_rewrite multiple mysql oop pageing pagerank paypal pdf php problem protocol query radio random recursion recursiveloop regex remote script search server sessions sms soap source space sql strip_tags subversion support! survey syntax system table template tutorial update upload url validator variable video web window.onbeforeunload=closeme; xml youtube






