-4

In my project , I have used dates in DD-MON-YYYY format and stored it in the MySql table as data type = "Text"

example: 18-JUN-2013

I have used JavaScript date picker to select dates from the calendar.

Blockquote

Now, I really want to perform is:

1: To find date difference between two dates when retrieved from MySql database using PHP.

2: To Add 359 days to retrieved date and display future date.

Blockquote

Note: Date format must be DD-MON-YYYY.

halfer
  • 19,824
  • 17
  • 99
  • 186
Vikram
  • 309
  • 3
  • 6
  • 19
  • 4
    I would recommend you store dates in MySQL using date fields and worry about converting them to your output formats on output. This is best practice. In PHP, you should investigate the DateTime and DateInterval classes, these will allow you to do almost anything you need with dates. – Mike Brant Jun 18 '13 at 14:53
  • you should store the date in strtotime format and perform all the database action from this. date difference and various date action can be performed very easily using this. – Harshal Jun 18 '13 at 14:56

1 Answers1

2

Really you should be storing your dates as proper date types in the database, output formatting can always be controlled. This would expose all the database tools for searching, comparing and sorting dates correctly.

However, as you don't have this you will need to use PHP's strtotime method to convert your string dates into unix timestamps which can then be used for comparisons and calculations

See the answer to this question for date differences:

How to calculate the difference between two dates using PHP?

For adding time to a date you could do:

$newDate = strtotime('18-JUN-2013 + 359 days');
Community
  • 1
  • 1
fullybaked
  • 4,117
  • 1
  • 24
  • 37