Jump to content

Recommended Posts

Hello-

 

I have an array with the following data:

Array
(
    [0] => Array
        (
            [0] => Del Date/Time:01/31/0811:20 AM
        )

    [1] => Array
        (
            [0] => 01/31/0811:20 AM
        )
)

$var = $array[1][0];  //this gives me 01/31/0811:20 AM
$date = substr($var, 0, 11); //this gives me 01/31/08
$deliv_date = date("Y-m-d", strtotime($date)); //this suppose to give me 2008-01-31

 

My problem is the last piece of code: $deliv_date = date("Y-m-d", strtotime($date)); 

It returns a date of 1969-12-31 but I need it to return 2008-01-31.  I echo $date and it is 01/31/08.  Much appreciation.

 

Link to comment
https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/
Share on other sites

code:

<?php
  $array = array(
    array('Del Date/Time:01/31/0811:20 AM'),
    array('01/31/0811:20 AM')
  );
  $var = $array[1][0];
  $date = substr($var, 0, ;
  $deliv_date = date("Y-m-d", strtotime($date));
  echo $deliv_date;
?>

output:

2008-01-31

 

What am I missing?

print each variable to see where the problem is:

 

<?php
  $array = array(
    array('Del Date/Time:01/31/0811:20 AM'),
    array('01/31/0811:20 AM')
  );
  print_r($array);
  $var = $array[1][0];
  print "\$var: $var\n";
  $date = substr($var, 0, ;
  print "\$date: $date\n";
  $deliv_date = date("Y-m-d", strtotime($date));
  print "\$deliv_date: $deliv_date\n";
?>

should produce:

Array
(
    [0] => Array
        (
            [0] => Del Date/Time:01/31/0811:20 AM
        )

    [1] => Array
        (
            [0] => 01/31/0811:20 AM
        )

)
$var: 01/31/0811:20 AM
$date: 01/31/08
$deliv_date: 2008-01-31

Yeah.  I figured out my issue.  I am screen scraping data and what was getting me is the html tags.  I went and viewed the source code and the array is as follows:

[1] => Array

        (

            [0] => <b>01/31/08<BR>11:20 AM</b>

        )

I had to use the following code:

 

echo $var =  trim(strip_tags($array[1][0]));
echo "<br>";
echo $d = substr($var, 0, ;
echo "<br>";
echo $deliv_date = date("Y-m-d", strtotime($d));

 

This gave me what I am needing.  Thanks for the help.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.