?
Solved

date

Posted on 2005-03-15
10
Medium Priority
?
120 Views
Last Modified: 2010-03-05
when i retrieve from database, the date is : 1104451200000

$time  = "1104451200000";  ###### this is 12:31:2004
       my @lt = localtime($time/1000);
        my ($year,$month,$day,$hour,$minute,$second) = ($lt[5]+1900,$lt[4]+1,$lt[3]+1,$lt[2],$lt[1],$lt[0]);
        print "        $month:$day:$year \n";   #### this gives me  12:20:2004...... 1 day less


i get 1 day less:

ex) if the date in databse is         12:31:2004
what i get is  12:30:2004

any ideas????

Rahul
0
Comment
Question by:shahrahulb
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 750 total points
ID: 13550029
It could be where you say $lt[3]+1 . The day range will be from 1..31, not 0..30 so no need to add 1 like for month
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 750 total points
ID: 13550081
use POSIX 'strftime';
$time = 1104451200000;
print strftime "%m:%d:%Y\n", localtime($time/1000);


0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13550379
i found the solution :
instaed of my @lt = localtime($time/1000);  it should be my @lt = gmtime($time/1000);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Tintin
ID: 13550496
My solution works also, and I think it is a lot neater.
0
 
LVL 85

Expert Comment

by:ozo
ID: 13550558
I agree, although it may depend on the difference beween localtime and gmtime, and exactly when you want the day to change.
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13577409
can someone please close this question as i got the solution on my own....
0
 
LVL 85

Expert Comment

by:ozo
ID: 13578020
I don't think your solution works on the last day of the month.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans
Suggested Courses

621 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