Link to home
Start Free TrialLog in
Avatar of Overthere
Overthere

asked on

PHP5 and extracting MS SQL Server DateTimeStamp from table

Hello folks,

     I have a MS Sql Server table. One of the columns is a DateTime stamp.
I need only to extract the date. When I use the code:

 
$hiredate = $row["HireDate"];

Open in new window


gives me can "not convert to string" which I understand.
I need to only pull the date and not time, I know I can reformat the date once I successfully
assign it to a variable but that's the problem -
How do I assign it to a variable?  Can I reformat the date before assigning it to the variable?
I see all sorts of info about date/time in the php manual but they are using constants, not something pulled
from a table...
SOLUTION
Avatar of Peos John
Peos John
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't understand because almost everything that comes back from a database is in text format unless it is in one of the binary data types.  Can you show us the CREATE TABLE or structure definition?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Overthere
Overthere

ASKER

You have a point Mufur - converting within a sql query is very possible and I think more feasible.
 I can also convert it to a date in php for date comparisons.
Thank you everyone for responding, its as always appreciated...
Just thought I would share this snippet.
This is the sql query that worked very well for me....

SELECT LEFT(CONVERT(VARCHAR, HireDate, 120), 10)as HireDate, Paid FROM MyTable WHERE RecId = 1001

Open in new window

The SQL Query that worked so well for is not shown in your Accepted Solution while a similar solution is shown in my post above.