Jump to content

Recommended Posts

Hello everyone,

 

I'm trying to extract just the date from a datetime stamp within the SQL syntax.  When I run the sql it returns an error.  The code is below.  The error returned is as follows:

 

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in on line ...

 

The statement runs fine without the convert() function within the sql statement.  Of course.

 

What could I be doing wrong?  Thanks for any help on this one.  :confused:

 


<?php

//making the query from table time_clock
$Query = "SELECT * FROM time_clock 
		  JOIN employees ON time_clock.Emp_Id 
		  WHERE time_clock.Clockin 
		  BETWEEN convert(varchar(10),'2008-10-20', 101) AND convert(varchar(10),'2009-01-13', 101) AND time_clock.Emp_Id=53 ";
$Result = mysql_query( $Query );

while( $Row = mysql_fetch_object( $Result ) ) {

	$output = $Row->Emp_Id." ". $Row->FirstName . " " . $Row->LastName . " ".$Row->Clockin." \n";
}

die($output);

?>

Hello Everyone,

 

I've figured out the correct syntax for my problem.  Below in the corrected SQL statement.  I've added an SQL function called DATE_FORMAT().  This will format the date per the format parameters indicating at the following url: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

 

The Clockin is the field I want to format in my database, then I pass those formatted dates to another field called FormattedDate and use that as my output.  Hope this can useful to someone out there.

 

 


<?php

$Query = "SELECT *, DATE_FORMAT( Clockin, '%d-%m-%Y' ) AS FormattedDate FROM time_clock 
		  JOIN employees ON time_clock.Emp_Id 
		  WHERE time_clock.Clockin 
		  BETWEEN '2008-10-20' AND '2009-01-13' AND time_clock.Emp_Id=53 AND time_clock.LocationID=41 ";
$Result = mysql_query( $Query );

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.