Jump to content

$time = time(); Need Something better with microseconds


nightkarnation

Recommended Posts

Hey Guys.

 

I have the following problem on mysql database:

 

With php using $time = time(); I receive for example: 1302638294

 

I need something more accurate than this because sometimes I receive on my DB the same value (2 times) and it generates some conflicts due to the fact I am using this information to know which user sent some information, first, second, etc...

 

Does anyone have any suggestions on how I can solve this problem?

Thanks a lot in advance!

Cheers.

Link to comment
Share on other sites

Yes I already tried that.

Thanks a lot.

 

The problem is that for example on my DB...the value from $time = time(); is being stored on a field called Raw_Time with Data Type int(32)

And when I use $time = microtime(); I get on DB a 0 value...

 

And I need the int type on the Raw_Time because I need to: ORDER BY `CLICKING_HISTORY`.`Raw_Time` DESC LIMIT 0 , 10

 

I apologize for not explaining this before.

Looking forward for any suggestions or ideas.

Thanks a lot in advance!

Link to comment
Share on other sites

Thanks a lot for all your help!

 

Markjoe

 

I tried your code and I get a 4 value number...

 

And based on that I tried:

 

$time = time(); //for Raw_Time
$timeSec = microtime(true)*10000;
$time = $time . $timeSec;

 

But instead of adding the value with 4 numbers after the time, I think its being added to the time result.

 

Any ideas on how I can format this better than what I am doing?

Link to comment
Share on other sites

 

You could prefix the timestamp with the user's ID (primary key)?

 

 



//pull some user data making sure you include userID


$uniqueTime = $row['userID'] . time();


//insert data into appropriate table

 

 

then to find the time

 

 

//pull unique time


$timeOfAction = time() - substr($row['uniqueTime'], 1);


echo 'Action made ' . $timeOfAction . ' seconds ago.';

 

 

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.