Jump to content

how to save timestamp in mysqli without commas


kalster

Recommended Posts

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);

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.

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?

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.

'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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.