Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

change gmt+ date

Posted on 2010-11-16
11
Medium Priority
?
311 Views
Last Modified: 2012-05-10
I get date in this form

14 nov. 10
19:17:32 GMT+01:00

want
2010-11-14
0
Comment
Question by:rgb192
[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
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34149519
date('Y-m-d')
0
 
LVL 14

Expert Comment

by:Ali Kayahan
ID: 34149521
echo date("Y-m-d",strtotime("14 nov. 10 19:17:32 GMT+01:00")) ;
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34149529
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

by:Ali Kayahan
ID: 34149553
Ray wasnt this such a hard question for you :P
0
 

Author Comment

by:rgb192
ID: 34149775
 $french="14 nov. 10
19:17:32 GMT+01:00";


this works
echo date("Y-m-d",strtotime("14 nov. 10 19:17:32 GMT+01:00")) ;



but this doesnt
echo date("Y-m-d",strtotime($french)) ;


maybe because date is in french


0
 
LVL 14

Expert Comment

by:Ali Kayahan
ID: 34149862
can you please try by adding this line at the top ;

setlocale(LC_ALL,"fr_CA");
0
 

Author Comment

by:rgb192
ID: 34149883
output
1970-01-01


<?php
setlocale(LC_ALL,"fr_CA");
  $french="14 nov. 10
19:17:32 GMT+01:00";
//echo date("Y-m-d",strtotime("14 nov. 10 19:17:32 GMT+01:00")) ;
echo date("Y-m-d",strtotime($french)) ;
?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34150197
Works OK for me without any locale setting.  PHP 5.3.3 on Linux
http://www.laprbass.com/RAY_strtotime.php?s=14+nov.+10+19%3A17%3A32+GMT%2B01%3A00

Outputs:
BINGO
14 nov. 10 19:17:32 GMT+01:00 WORKS WITH strtotime()
THE INTEGER TIMESTAMP VALUE IS 1,289,758,652
THE ISO8601 DATETIME STRING IS 2010-11-14T12:17:32-06:00
THE TEXTUAL DATE IS Sunday 14th of November 2010 12:17:32 PM

Here is my test script.
<?php // RAY_strtotime.php
error_reporting(E_ALL);

// PHP 5.1+  SEE http://us3.php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

// IF WE HAVE INPUT FROM THE URL QUERY STRING
if (!empty($_GET["s"]))
{
    // USE strtotime() FUNCTION TO MAKE A TIMESTAMP
    // MAN PAGE: http://us.php.net/manual/en/function.strtotime.php
    $unix_timestamp = strtotime($_GET["s"]);

    // TEST FOR SUCCESS OR FAILURE
    if ($unix_timestamp === FALSE)
    {
        echo "<strong>HONK!</strong><br /> <u>{$_GET["s"]}</u> NOT USEFUL WITH strtotime() <br/><br/><br/><br/>";
    }

    // ON SUCCESS, PRINT THE RESULTS
    else
    {
        echo "<strong>BINGO</strong><br /> <strong><u>{$_GET["s"]}</u></strong> WORKS WITH strtotime() <br/>";
        echo "THE INTEGER TIMESTAMP VALUE IS ";
        echo number_format($unix_timestamp) . "<br />";

        // FORMAT ISO AND HUMAN-READABLE DATES
        // MAN PAGE: http://us.php.net/manual/en/function.date.php
        $y = date('c', $unix_timestamp);
        echo "THE ISO8601 DATETIME STRING IS $y<br />";
        $z = date('l dS \o\f F Y g:i:s A', $unix_timestamp);
        echo "THE TEXTUAL DATE IS $z<br />";
    }

    echo PHP_EOL;
} // END OF PROCESSING INPUT
// PUT UP THE FORM
?>
<html>
<head>
<title>TEST THE PHP FUNCTION strtotime()</title>
</head>
<body onload="document.f.s.focus()">
<form name="f" method="get">
<br />TO TEST A STRING FOR A VALID DATE/TIME, TYPE IT HERE:<input name="s" />
<input type="submit" value="GO" />
</form>

TRY TESTING SOME OF THESE STRINGS (CLICK THE LINK, OR COPY AND PASTE INTO THE FORM):


<?php function t($str)
{
    echo "<br/><a href=\"http://www.laprbass.com/RAY_strtotime.php?s=" . urlencode($str) . "\">$str</a>\n";
}
t('- 3 hours');
t('tomorrow');
t('tomorrow 3:15:25 pm');
t('March 15, 1986');
t('yesterday');
t('yesterday + 1 week');
t('next year');
t('now');
t('now + 627 hours 15 minutes');
t('tomorrow midnight');
t('tomorrow 1:35pm');
t('last Tuesday');
t('three days ago');
t('- 3 days');
t('A VALID TIME');
t('A BOGUS TIME');
t('A NON-BOGUS TIME');
t('s time');
t('t time');
t('u time');
t("Avogadro's Constant");
t("Wednesday November, 10 2010 1:01pm");
t("Wednesday, November 10 2010 1:01pm");
?>
<br/>Note: Your local time may vary.  This server is in US Central Time
</body>
</html>

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 34150263
Looks like the linefeed in the middle of the date causes trouble.  Copy / paste into an input control eliminates this character.  So it makes sense to eliminate extraneous whitespace in the date/time strings.  Line 16 of the code snippet does the trick.
<?php
error_reporting(E_ALL);

// PHP 5.1+  SEE http://us3.php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

// setlocale(LC_ALL,"fr_CA");

  $french="14 nov. 10
19:17:32 GMT+01:00";

echo date("Y-m-d",strtotime("14 nov. 10 19:17:32 GMT+01:00")) ;
echo date("Y-m-d",strtotime($french)) ;

// CORRECT FOR LINEFEEDS WITH PREG_REPLACE EXAMPLE 5
$french = preg_replace('/\s\s+/m', ' ', $french);
echo date("Y-m-d",strtotime($french));

Open in new window

0
 
LVL 14

Expert Comment

by:Ali Kayahan
ID: 34150411
Your string also works fine for me without setlocale
0
 

Author Closing Comment

by:rgb192
ID: 34150688
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question