Welcome Guest, Not a member yet? Register   Sign In
Convert timestamp to tick
#11

Here are a couple of methods you can play with:

PHP Code:
// -----------------------------------------------------------------------

/**
 *  Converting a Unix timestamp to DateTime Ticks
 *
 * Equation: (UNIX_TIMESTAMP * 10000000) + 621355968000000000
 */
if ( ! function_exists('timeToTicks'))
{
 
   function timeToTicks($time)
 
   {
 
       return number_format(($time 10000000) + 6213559680000000000'.''');
 
   }
}

// -----------------------------------------------------------------------

/**
 * Converting DateTime Ticks to a Unix timestamp in PHP
 *
 * Equation: (TICKS – 621355968000000000) / 10000000
 */
if ( ! function_exists('ticksToTime'))
{
 
   function ticksToTime($ticks)
 
   {
 
       return ($ticks 621355968000000000) / 10000000;
 
   }


Good luck...
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#12

(03-08-2018, 10:07 AM)InsiteFX Wrote: I found this article on stackoverflow:

CURRENT_TIMESTAMP in milliseconds

Which may be able to help you out.

Thanks
Reply
#13

(03-08-2018, 03:45 PM)InsiteFX Wrote: Here are a couple of methods you can play with:

PHP Code:
// -----------------------------------------------------------------------

/**
 *  Converting a Unix timestamp to DateTime Ticks
 *
 * Equation: (UNIX_TIMESTAMP * 10000000) + 621355968000000000
 */
if ( ! function_exists('timeToTicks'))
{
 
   function timeToTicks($time)
 
   {
 
       return number_format(($time 10000000) + 6213559680000000000'.''');
 
   }
}

// -----------------------------------------------------------------------

/**
 * Converting DateTime Ticks to a Unix timestamp in PHP
 *
 * Equation: (TICKS – 621355968000000000) / 10000000
 */
if ( ! function_exists('ticksToTime'))
{
 
   function ticksToTime($ticks)
 
   {
 
       return ($ticks 621355968000000000) / 10000000;
 
   }


Good luck...

I need for mysql not php,can i convert it to mysql?
Reply
#14

You should be able to convert it to MySQL.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#15

(03-09-2018, 06:15 AM)InsiteFX Wrote: You should be able to convert it to MySQL.

Thanks
Reply
#16

Here are a couple more SQL Selects you can try:

PHP Code:
SELECT FROM_UNIXTIME((`TIMESTAMP` / 1000)) as mytime FROM `table`;

SELECT FROM_UNIXTIME((`TIMESTAMP` / 1000)) as mytimeTIMESTAMP mod 1000 as msec FROM `table`; 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#17

(03-09-2018, 02:00 PM)InsiteFX Wrote: Here are a couple more SQL Selects you can try:

PHP Code:
SELECT FROM_UNIXTIME((`TIMESTAMP` / 1000)) as mytime FROM `table`;

SELECT FROM_UNIXTIME((`TIMESTAMP` / 1000)) as mytimeTIMESTAMP mod 1000 as msec FROM `table`; 

Woooooooow Thanks Heart
Reply
#18

(03-09-2018, 10:47 PM)omid_student Wrote:
(03-09-2018, 02:00 PM)InsiteFX Wrote: Here are a couple more SQL Selects you can try:

PHP Code:
SELECT FROM_UNIXTIME((`TIMESTAMP` / 1000)) as mytime FROM `table`;

SELECT FROM_UNIXTIME((`TIMESTAMP` / 1000)) as mytimeTIMESTAMP mod 1000 as msec FROM `table`; 

Woooooooow Thanks  Heart

But it was wrong and return Null
Reply
#19

my code in java is
public String timeAgo(long millis) {
long diff = new Date().getTime() - millis;

double seconds = Math.abs(diff) / 1000;
double minutes = seconds / 60;
double hours = minutes / 60;
double days = hours / 24;
double years = days / 365;
}
In mention code,function current now minus my time according millisecond
So i have to convert timestamp to millisecond
Reply
#20

You could use the PHP DateTime::format

DateTime::format
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB