Solved

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

Posted on 2013-05-23
3
257 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 108

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now