Solved

# date

Posted on 2005-03-15
Medium Priority
117 Views
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
Question by:shahrahulb
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2
• 2
• +1

LVL 19

Accepted Solution

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

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

ID: 13550379
i found the solution :
instaed of my @lt = localtime(\$time/1000);  it should be my @lt = gmtime(\$time/1000);
0

LVL 48

Expert Comment

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

LVL 84

Expert Comment

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

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

LVL 84

Expert Comment

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

## Featured Post

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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
Course of the Month12 days, 5 hours left to enroll