Kiko has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I haven't done much work with MySql especially Manipulating the date and time. I don't have any code yet to put up but i'm trying to do the following:

1. If you register for a course two weeks in advance then you only pay the regular price of the course.

2. If you register between 2weeks and 1day before the course then you pay the price of the course plus a fine.

3. If you register the same day of the course meaning 24hrs or less then you pay the price of the course plus a bigger fine.

4. Also, if a person registers for two courses in the same city they get a discount of %25 of the price of each course.

I don't know if MySql has features that can do this for you or if i'm just gonna have to do it in Perl. If anyone has done something like this before and wouldn't mind sharing their code i would really appreciate it. And if not please direct me to a tutorial that can help me solve these problems.

Thans in Advance,
Kiko

Replies are listed 'Best First'.
Re: MySql Date and Time Manipulation
by techy (Scribe) on Oct 19, 2001 at 21:25 UTC
    The MySQL documentation on date and time formats can be found here.

    In particular, take a look at DATE_ADD() and DATE_SUBTRACT(), which will return a date offset from a given date by a certain amount (i.e. 1 DAY).
    Thanks,
    TECHy

Re: MySql Date and Time Manipulation
by George_Sherston (Vicar) on Oct 19, 2001 at 20:42 UTC
    I do all that kind of thing by storing my dates as the 10-digit time integer. So I don't have to learn how MySQL does dates, I save a tiny bit of space, and all my favourite perl date functions and modules have something they can get their teeth into. Plus it's very easy to add or subtract 24 * 60 *60.

    There's some more on this here

    § George Sherston