ainoy31 Posted February 4, 2008 Share Posted February 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/ Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 $date = substr($var, 0, 11); //this gives me 01/31/08 That will give you a value of '01/31/0811:'. I think you are looking for: $date = substr($var, 0, ; //this gives me 01/31/08 Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/#findComment-457687 Share on other sites More sharing options...
ainoy31 Posted February 4, 2008 Author Share Posted February 4, 2008 Thanks for the reply. I have tried echo $d = substr($var, 0, ; as suggested and it gives me 01/31. Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/#findComment-457692 Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/#findComment-457693 Share on other sites More sharing options...
ainoy31 Posted February 4, 2008 Author Share Posted February 4, 2008 That is a good question. I do not know why when I use the substr($var, 0, , it does not give me what you are getting. I am trying to figure out why it only works for me when I use substr($var, 0, 11). Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/#findComment-457703 Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/#findComment-457706 Share on other sites More sharing options...
ainoy31 Posted February 4, 2008 Author Share Posted February 4, 2008 I know.... It is frustrating to me... I have echoed everything and I get the date as 01/31/08. Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/#findComment-457715 Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 There is no way the above code will be different for you. Is there more to the script that you aren't sharing? Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/#findComment-457728 Share on other sites More sharing options...
ainoy31 Posted February 4, 2008 Author Share Posted February 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89380-solved-date-in-an-array-issue/#findComment-457746 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.