CodeIgniter Forums
Convert timestamp to tick - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Convert timestamp to tick (/showthread.php?tid=70200)

Pages: 1 2 3


RE: Convert timestamp to tick - InsiteFX - 03-08-2018

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


RE: Convert timestamp to tick - omid_student - 03-08-2018

(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


RE: Convert timestamp to tick - omid_student - 03-08-2018

(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?


RE: Convert timestamp to tick - InsiteFX - 03-09-2018

You should be able to convert it to MySQL.


RE: Convert timestamp to tick - omid_student - 03-09-2018

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

Thanks


RE: Convert timestamp to tick - InsiteFX - 03-09-2018

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



RE: Convert timestamp to tick - omid_student - 03-09-2018

(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


RE: Convert timestamp to tick - omid_student - 03-09-2018

(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


RE: Convert timestamp to tick - omid_student - 03-10-2018

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


RE: Convert timestamp to tick - InsiteFX - 03-10-2018

You could use the PHP DateTime::format

DateTime::format