SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with strftime and date

    Hi guys,

    I have tried for hours to work this out but I'm giving up.
    My code works fine for strftotime and English dates (i.e. Tuesday, 21st Oct 2008) but when I use strftime and setlocale it only gives me "torsdag, 1. januar 1970" in Norwegian.
    So the setlocale seems to work but I'm not getting the correct date from the database (DATE).
    Could anyone please tell me what's wrong in my code?

    Code PHP:
    $newslist = @mysql_query('select title, description, date, place, id
    	from course where date > NOW() order by date');
    	if (!$newslist) {
    	exit('<p>Error performing query: ' . mysql_error() . '</p>');
    	}
    	while ($news = mysql_fetch_array($newslist)) {
    	setlocale(LC_TIME, "no_NO");
    	$title = $news['title'];
    	$intro =  $news['description'];
    	$date = $news['date'];
    	$place = $news['place'];
    	$timestamp = strftime($date);
    	$date = strftime('%A, %e. %B %Y', $timestamp);	
     
    	//Display courses
    	echo "<p><span class='newstitle'>$title</span><br />" . 
    "<span class='newsintro'>$intro</span><br />" . 
    "<span class='coursedate'>Dato: $date  </span><span class='coursedate'>Sted: $place</span><br class='clear'/><br />";
    	}

    Thanks!

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Alter the following line:
    PHP Code:
    $timestamp strftime($date); 
    to:
    PHP Code:
    echo 'date: ' $date '<br />';
    $timestamp strftime($date);
    echo 
    'timestamp: ' $timestamp
    What is the output of that?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    date: 2008-11-11
    timestamp: 2008-11-11

    It gives the correct date but in the input format.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Maybe it's too early, and I'm being a little obtuse, but shouldn't this line...

    PHP Code:
    $timestamp strftime($date); 
    be...

    PHP Code:
    $timestamp strtotime($date); 
    ?

    SilverB.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dato: tirsdag, 11. november 2008 Sted: Oslo

    Perfect!

    Thanks a lot!

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    No problem.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •