Timestamp SQL date field with PHP time

scoutch29

Junior Member
Aug 8, 2010
17
0
0
Hi,

I have a small problem when comparing two dates (from and to) with each of those SQL fields (date_from, date_to) with the PHP time() function.

I would like the from date not to be lower than the microtime date specified and the to date not to exceed the current time. Additionally, I have a new date period which must not exceed the to date either (let's say: new_date).

Would someone kindly shed me some lights on this ?
 

KIAman

Diamond Member
Mar 7, 2001
3,342
23
81
Are you looking to make the comparison inside transact SQL or PHP? Can you provide some code so we can see what you are working with?
 

scoutch29

Junior Member
Aug 8, 2010
17
0
0
Hi, I'm looking for to compare between SQL fields from PHP. I do not have the codes, which is why I ask how it could be done ...

example:

SQL Fields:

cutoff
new_image_date
available_from_date
available_to_date

Now, the objective is to not exceed the available_to_date field period (microtime period) even though the new_image_date time range has been exceeded in days. The available_from_date would, then, take the new_image_date's place until the available_from_date reaches, as well, the available_to_date the same way the new_image_date field has reached its time period from the cutoff field. The cutoff field would be determined like this for the new_image_date time period:

PHP:
time() - 60 * 60 * 24 * cutoff;

which the 'cutoff' would be used with the object in this case. I do know how to retrieve new image time period but the rest explained on the above, I'm unable to.

Any help would be appreciated on this.
 

Kr@n

Member
Feb 25, 2010
44
0
0
If I understand your problem well, you could always code your SQL query for it to return normalized strings (ODBC : yyyy-mm-dd hh:mi:ss.mmm or ISO : yyyy-mm-ddThh:mi:ss.mmm) that you would parse in PHP code in order to convert them back to timestamps.

This would also ensure database agnosticism (no datetime to int to timestamp trickery or whatever) ...

Another solution would be to use a PHP database connector (middleware) that does it for you (like AdoDB IIRC)


However, I think it may be a clever idea to provide your query the needed parameters (cutoff ?) and calculate the resulting dates in SQL ...

Hope That Helps ...


NOTE : I'm not sure I answered your question, because I have a feeling you are implying you cannot modify the SQL queries (have no access to them).Is that so ?
 

scoutch29

Junior Member
Aug 8, 2010
17
0
0
If I understand your problem well, you could always code your SQL query for it to return normalized strings (ODBC : yyyy-mm-dd hh:mi:ss.mmm or ISO : yyyy-mm-ddThh:mi:ss.mmm) that you would parse in PHP code in order to convert them back to timestamps.

This would also ensure database agnosticism (no datetime to int to timestamp trickery or whatever) ...

Another solution would be to use a PHP database connector (middleware) that does it for you (like AdoDB IIRC)


However, I think it may be a clever idea to provide your query the needed parameters (cutoff ?) and calculate the resulting dates in SQL ...

Hope That Helps ...


NOTE : I'm not sure I answered your question, because I have a feeling you are implying you cannot modify the SQL queries (have no access to them).Is that so ?

The cutoff means the maximum value in days when the time expires. I'm only looking for to do this in mySQL. As for the access, no actually ... I do have access but I just cannot apply the query as expected and simply looking for a way to achieve this ...

As for the date format, it's yyyy-mm-dd. As explained on my first post, the specified date fields (from, to and new date) are already timestamped fields. There's no need to convert them back to timestamps ...

Any solution (code) of what it could be ?
 

Kr@n

Member
Feb 25, 2010
44
0
0
If all of your data is available in your query (all data is in fields), then it is quite trivial to calculate the needed values in SQL.

Alas, I do not really know what you want to do, and thus cannot provide you specific code snippets. What is the difficulty : adding your (integer ?) offset to your timestamps, comparing your timestamps (I do not know MySQL very well, but I'm pretty sure some case ... when and < > operators would do the trick).

If you still need some help, can you please provide the SQL types of the involved fields (the CREATE TABLE script for the said table will do), and describe your calculation (in pseudo-code / math) ?


Always useful : http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Hope That Helps ...
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |