Jump to content

how to save timestamp in mysqli without commas


kalster
Go to solution Solved by 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);

Edited by kalster
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by kalster
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

'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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.