| | |
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: 149
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.12 or 5.3.1
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.12 or 5.3.1
likewise sql now()
is equivalent to php time()
is equivalent to php time()
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
•
•
Join Date: Jul 2008
Posts: 149
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.12 or 5.3.1
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.12 or 5.3.1
![]() |
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 |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms snippet soap source space speed sql static structure syntax system table tutorial up-to-date update upload url validation validator variable video web wordpress xml youtube






