Solved

email is 5 hours behind, sms 0 hours behind: how to sort

Posted on 2013-05-23
3
263 Views
Last Modified: 2013-05-26
I downloaded gmails and noticed the email time is 5 hours behind
my sms are in real time 0 hours behind


CREATE TABLE `email_doc` (
  `id` int(11) NOT NULL auto_increment,
  `unix_timestamp` bigint(20) default NULL,
  `from_email` varchar(200) default NULL,
  `from_name` varchar(200) default NULL,
  `to_email` varchar(200) default NULL,
  `to_name` varchar(200) default NULL,
  `subject` varchar(400) default NULL,
  `body` varchar(4000) default NULL,
  `real_id` varchar(30) default NULL,
  `checked` int(11) default NULL,
  `me_description` varchar(9000) default NULL,
  `client_description` varchar(4000) default NULL,
  `sms_type` tinyint(4) default NULL,
  `client_start` datetime default NULL,
  `client_end` datetime default NULL,
  `client_total` int(11) default NULL,
  `me_start` datetime default NULL,
  `me_end` datetime default NULL,
  `me_total` int(11) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `unix_timestamp` (`unix_timestamp`)
) ENGINE=MyISAM AUTO_INCREMENT=1758 DEFAULT CHARSET=utf8$$




select * from email_doc order by unix_timestamp

if email (real_id is not null), then the time is unix_timestamp +5 hours


$row->unix_timestamp+18000

is sms
real_id is null
$row->unix_timestamp


when I use php I see messages out of order

echo $row->unix_timestamp;
if (!empty($row->real_id)){
echo'<br>'.date("M j, g:i A", $row->unix_timestamp+18000);  
echo '<br>'.$row->subject;
}else{
  echo'<br>'.date("M j, g:i A", $row->unix_timestamp);
}

Open in new window



I want to order by time, not unix_timestamp



I think it would be best if I can sort using mysql query
0
Comment
Question by:rgb192
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 39193513
'unix_timestamp' is the date and time in seconds since Jan 1, 1970.  While you can format it or convert it to be 'human readable', it is time.  And since it is a single number, it sorts very well.  Other formats probably convert to unix_timestamp for most operations.
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39194991
Please read this article, where all of this sort of thing is explained -- either in the text or in the linked man page references and articles.  If you find it TLDR, take a break and then come back to it.  If you're going to write computer programming that is sensitive to DATETIME values you need to understand this stuff!
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

See especially: http://php.net/manual/en/function.date-default-timezone-set.php
0
 

Author Closing Comment

by:rgb192
ID: 39198445
based upon your suggestions I created another unix_timestamp column

thanks
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question