0

I have an array of Unix timestamps. I used the following code to make a file path of the timestamps array ($i is used later in a loop, but at first it gets value 0 and so it's correct):

$date = date('d-m-y', $timestamp[$i]);
$path = $dir . '/' . $date '.csv';

Let's say there many timestamps in the array. If i set $i = 0; $date is a string 06-01-13 (it returns the current day, though timestamp is many weeks old), and it ignores the timestamp. But if I replace $timestamp[$i] with 1257426933 the output string is correct (05-11-09).

What's wrong? My PHP version is PHP 5.3.10-1ubuntu3.4

3
  • 1
    Can you clarify what timestamp you are feeding and what date you are getting? Commented Jan 6, 2013 at 13:32
  • Try var_dump( $timestamp[$i] ); Commented Jan 6, 2013 at 13:32
  • See my other comment below. Commented Jan 6, 2013 at 14:30

1 Answer 1

1

Most likely is that the $timestamp[$i] value is not what you expected?

var_dump($timestamp);

date() will give the current date if the second parameter is empty or not present.

Sign up to request clarification or add additional context in comments.

3 Comments

Currently, array has following 6 values: var_dump($timestamp) array(6) { [0]=> int(1357426933) [1]=> int(1357430473) [2]=> int(1357434073) [3]=> int(1357437673) [4]=> int(1357441273) [5]=> int(1357498872) }
Wait a minute, there is a mess in my timestamp function, I have a look at it
Yes, of course. My fault. Timestamps were faulty as you can see. I give a wrong fromat to the function which makes them. So strtotime needs times in yyyy-mm-dd format... SOLVED

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.