kalster Posted June 4, 2013 Share Posted June 4, 2013 (edited) i searched the net and can't fine a solution to this problem. i have this code below and when i try to save it in the mysql database, it inputs the value with commas in it. how to save without the commas. thank you. $DateTime = gmdate("M d Y h:i:s a", time());$Timestamp = strtotime($DateTime); Edited June 4, 2013 by kalster Quote Link to comment Share on other sites More sharing options...
kicken Posted June 4, 2013 Share Posted June 4, 2013 What commas? There are no commas in either of those variables with the code given. For what it's worth also, that code is the same as just doing $Timestamp = time(); There is no need for the gmdate() and strtotime() functions. Quote Link to comment Share on other sites More sharing options...
kalster Posted June 4, 2013 Author Share Posted June 4, 2013 (edited) when i save the timestamp to the database, the timestamp field as commas it in, for example, 1,370,311,979. Notice: A non well formed numeric value encountered in... this is what happens when i try to get the timestamp from the field Edited June 4, 2013 by kalster Quote Link to comment Share on other sites More sharing options...
DavidAM Posted June 4, 2013 Share Posted June 4, 2013 What is the mySql datatype of the column where you store that value? Maybe you should show all of the code from $Timestamp = ... up to where you put it in the database. Are you using number_format()? $Timestamp, as kicken said, will NOT have commas in it based on the code you posted. If the commas are in the database, then you have other code adding them. Where do you see the commas? Is it your display code that retrieves the data and then adds the commas before displaying it? Quote Link to comment Share on other sites More sharing options...
kicken Posted June 4, 2013 Share Posted June 4, 2013 Then you're doing something to add those commas, such as running the number through number_format before saving it or after retrieving it. Check the DB value using something like phpMyAdmin, mysql cli tool or Workbench to see what the value of the column really is. If you have commas in the number there then that also means your storing the value in the wrong field type because an INT field (which you should be using for numbers) wouldn't allow such a value to be stored. On a side note, since your storing a date you should be using a DATETIME or TIMESTAMP column type and putting the value into the db using the YYYY-MM-DD HH:mm:ss format, rather than using an INT and a unix timestamp. Quote Link to comment Share on other sites More sharing options...
kalster Posted June 4, 2013 Author Share Posted June 4, 2013 'Timestamp` INT(11) NOT NULL DEFAULT '0', "INSERT INTO users (Timestamp) VALUES (UNIX_TIMESTAMP())"; its a very basic example as i am using a unix timestamp. therefore, nothing is adding to the code. the data type is int using innodb for the engine. i see the commas in the database for that field Quote Link to comment Share on other sites More sharing options...
Solution kalster Posted June 4, 2013 Author Solution Share Posted June 4, 2013 when i clicked the field in the mysql program, the commas were not there. for some reason the commas where displayed until i clicked the field to edit it. solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.