storing date mysql

Thread Solved

Join Date: Oct 2007
Posts: 42
Reputation: rohitrohitrohit is an unknown quantity at this point 
Solved Threads: 2
rohitrohitrohit's Avatar
rohitrohitrohit rohitrohitrohit is offline Offline
Light Poster

storing date mysql

 
0
  #1
Mar 12th, 2009
hi all,
Donn't know much php...........
i want that when user register,his registration date store in db.i want to use server date not his system date in db.

thankx in adva...
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 835
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 136
Sponsor
pritaeas's Avatar
pritaeas pritaeas is online now Online
Practically a Posting Shark

Re: storing date mysql

 
0
  #2
Mar 12th, 2009
php already uses the server's date.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 258
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: storing date mysql

 
0
  #3
Mar 12th, 2009
i want that when user register,his registration date store in db.i want to use server date not his system date in db.
Php uses the server date, unlike other languages it is not reliant on the users system date and time.
Do you need help coding this or was it just a question?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 42
Reputation: rohitrohitrohit is an unknown quantity at this point 
Solved Threads: 2
rohitrohitrohit's Avatar
rohitrohitrohit rohitrohitrohit is offline Offline
Light Poster

Re: storing date mysql

 
0
  #4
Mar 12th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 258
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: storing date mysql

 
0
  #5
Mar 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 148
Reputation: mschroeder is on a distinguished road 
Solved Threads: 25
mschroeder mschroeder is offline Offline
Junior Poster

Re: storing date mysql

 
0
  #6
Mar 12th, 2009
Store a UNIX Timestamp in that mysql column.

  1. <?php
  2. $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
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,335
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 163
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: storing date mysql

 
0
  #7
Mar 12th, 2009
likewise sql now()
is equivalent to php time()
Failure is not an option It's included free
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 148
Reputation: mschroeder is on a distinguished road 
Solved Threads: 25
mschroeder mschroeder is offline Offline
Junior Poster

Re: storing date mysql

 
0
  #8
Mar 12th, 2009
or UNIX_TIMESTAMP()
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 42
Reputation: rohitrohitrohit is an unknown quantity at this point 
Solved Threads: 2
rohitrohitrohit's Avatar
rohitrohitrohit rohitrohitrohit is offline Offline
Light Poster

Re: storing date mysql

 
0
  #9
Mar 13th, 2009
i did as u told me in last thred,i insert a recode but when i see column Registration_date it shows 0000-00-00 00:00:00?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 148
Reputation: mschroeder is on a distinguished road 
Solved Threads: 25
mschroeder mschroeder is offline Offline
Junior Poster

Re: storing date mysql

 
0
  #10
Mar 13th, 2009
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)
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC