Remove timestamp from row

can anyone get some code to hide the timestamp from the string. I used this code to get the date from a string, suppose that

$date_string = "02/06/2011 11:00 am - 2:00 pm";

$date = strtotime($date_string);
$date = date('m/d/y', $date);

But the output I get is like this

 1/1/70

Please suggest the best way that I could implement for this to work. I want it to show as

02/06/2011
+3
source share
5 answers

If the date you are looking for is already in the string and all you want to do is delete the time range, you do not need any date manipulation. Just delete everything after the space (if the format date_stringremains consistent).

$date_string = "02/06/2011 11:00 am - 2:00 pm";
$date = explode(" ",$date_string);
echo $date[0];

Or even simpler (but untested)

echo strtok($date_string," ");  //http://codepad.org/Or1mpYOp

PHP.NET:strtok

PHP.NET:explode

+4
$date = strtotime($date_string);
$date = getdate($date);
$date = $date['mon'] . '/' . $date['mday'] . '/' . $date['year']
+3

02/06/2011 11:00 am - 2:00 pm - , , , , $date_string, $date, strtotime('02/06/2011 11:00 am - 2:00 pm'); false, date('m/d/y', $date) 01/01/1970.

-

$date_string = "02/06/2011 11:00 am - 2:00 pm";
$date_exploded = explode('-',$date_string);

$date = strtotime($date_exploded[0]);
$date = date('m/d/y', $date);
echo $date;
+1

, - , , 00/00/00 [00] - , , mm/dd/yy [yy], dd/mm/yy [yy]. strtotime locale , .

, preg . :

/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})/

gives an array

0=> 02/06/2011
1=> 02
2=> 06
3=> 2011

Then use mktime to create a unix timestamp.

Other approaches include using substr to retrieve a fixed-length string, or using a space to retrieve words.

0
source

If your string is already a date.

$ date = substr ($ records [$ datetime, 0, 10);

0
source

Source: https://habr.com/ru/post/1772614/


All Articles