SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Showing date from MSSQL row

    Hi Guys!

    I am tryng to show a date which is stored in a MSSQL database (datetime) field (example: 6/1/2010 12:00:00 AM).

    Here is the code I am using:

    PHP Code:
    <?=strftime("%d-%m-%Y"strtotime ($row_Recordset1['inceptiondate'])); ?>
    The date is always getting displayed like this "31-12-1969" even thoughe the month, day and year are all wrong.

    Any ideas?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    sounds like a php problem to me
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    sounds like a php problem to me
    That's what I originally thought but when I try and echo out the date without any formatting, I get this error:

    PHP Code:
    PHP Catchable fatal errorObject of class DateTime could not be converted to string in E:\web\inshorecom0\htdocs\submissions.php on line 61 

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    still sounds like a php error
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    still sounds like a php error
    Argghh!!! When I echo out the same thing from a MySQL database it works fine but from MSSQL it gives me this. Do I need to change the SQL query?

    Here's what im using..

    PHP Code:
    SELECT FROM submissions where department='".$_GET['sort']."' 

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    no, you do not ~need~ to change your query, but i always advise people against using the dreaded, evil "select star" in production applications

    let the query return the datetime value as a datetime value, and format it with php

    sorry, i can't help you do that, i don't do php and this is the wrong forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    no, you do not ~need~ to change your query, but i always advise people against using the dreaded, evil "select star" in production applications

    let the query return the datetime value as a datetime value, and format it with php

    sorry, i can't help you do that, i don't do php and this is the wrong forum
    Ok I managed to figure it out using date_format (PHP).

    I have another question: The date in the table is in this format: 6/1/2010 12:00:00 AM

    How can I write a query to check if the year is 2010?

    Thanks in advance.

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    WHERE YEAR(inceptiondate)=2010 is the simplest way of doing it, although it isn't very efficient

    an efficient way would be
    Code:
    WHERE inceptiondate >= '2010-01-01'
      AND inceptiondate  < '2011-01-01'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •