0

let say i have a date Jun 9 2008 12:00AM and want to calculate how many days from NOW. can i do it using php ?

Note: The possible date can also be returned as 09/06/2008.

Try to use DATEDIFF frm http://msdn.microsoft.com/en-us/library/ms189794.aspx but no luck..

fancyPants
  • 49,071
  • 32
  • 84
  • 94
redcoder
  • 2,115
  • 4
  • 21
  • 23
  • Possible duplicate of http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php – CodeZombie Jun 27 '12 at 07:03

3 Answers3

0

You should use mysql DATEDIFF function.

xdazz
  • 154,648
  • 35
  • 237
  • 264
0

if you want to do it in php, so:

round((strtotime('now')-strtotime('Jun 9 2008 12:00AM'))/3600/24)

but DATEDIFF is much better

k102
  • 7,323
  • 6
  • 47
  • 68
0

You have tried the Microsoft SQL Server version of DATEDIFF, but your question is tagged as MySQL.

Try this one:

SELECT DATEDIFF(CURDATE(), yourDateColumn) FROM yourTable;

UPDATE (now that we know that it's actually MSSQL):

You need to clarify your question. What do you mean with "I have a date"? Is the date in the database? If yes, show the way you tried the DATEDIFF function. If it's a valid date in the database it doesn't matter how it is formatted and the following should definitely work:

SELECT DATEDIFF(d, yourDateColumn, GETDATE()) FROM yourTable;

Is the column type maybe not date but varchar? Then you can convert it like this:

SELECT CONVERT(datetime, yourDateColumnOrYourStringOrWhatever , format) ...

Here you can see which formats you can use.

Again, post more info or we can't help you. And I'm not going to guess around more.

fancyPants
  • 49,071
  • 32
  • 84
  • 94