Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Admin Date

  1. #1
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Admin Date

    Hey peepz,

    So I've been working on my admin section lately, before I start working on the main design. Now I've got a problem I'm not quite sure how to work out. I've got date and time settings in my admin page, which I can update, and the settings in the database will be updated. So if my date is for example:

    Code:
    d M Y
    I can call it from the database and post it as a date. Problem is, when I want to insert a newsitem, the date will also be posted. But I do not wish to actually post the date into the database, I would rather actually wish for the date format to change whenever I change this in my admin section. I don't think it's possible though, but I'm asking it anyway.

    I made it work with my private messages for example. Whenever someone changes their display name, that name will be shown in the private messages list, also the ones that have already been sent. I only wish for the date and time to do the same, otherwise my date and time admin section are of no use.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Wait, let me get this straight, you want to make it so each of your news items shares the same dates and times? Or do you mean like date and time offsets for different timezones or daylight savings areas?
    To answer whatever your question will be, yes this can be done and quite easily at that. To start with, I'd recommend you start using timestamps with your date values instead (especially if you are looking at the timezone usage) as this will greatly simplify your work. Get back as to what exactly you mean for the implementation of the time.

    [edit]
    Man I hate being tired. I gotcha now, you simply want to create a format for your time correct? Simple.
    First step, make sure you are using timestamps, this will make it easy. Use them for everything, from dates to times.
    Second step, when calling anything that requires the formatting, you need to query what the format is. I'd recommend somehow storing this with your common data in an array or object of common functionatlity.
    Third. Use the date() in combination with your timestamp:
    PHP Code:
    $postDate date($common->dateFormat$postTimeStamp); 
    for example.
    Does this answer your question?
    Last edited by Fou-Lu; 03-11-2007 at 10:26 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    Thanks a lot,

    I read it, and I think I will get this to work, with whatever I want/need. I have to say though, that I won't be checking it anytime soon, since I'm working on different things at the moment. But I'll be sure to have checked it by tonight, and see if it does what I want. Whatever happens, I'll post here again later today.

    Thanks again!

    [edit]
    I believe I also read it wrong :P I wish for the date format to change (for posts which have already been made aswell) when I change the value in the admin section...
    Last edited by Sylvester21; 03-11-2007 at 03:53 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Ok, you simply need to use a consistant data source for everything. Since I have recommended that you use a timestamp to store your data, you will need to update the posts as well.
    Best function for that would be strtotime(). This will allow you to pass your formatted date in and return a timestamp.
    Now, this could give you a problem, it has specified guidlines to follow, and unfortunatly I'm not 100% certain as to how it operates when it parses. However, you can simply check this by running a script to compare the output before you look at updating:

    PHP Code:
    <?php
    // I will assume that the value $newsDate has been queried already
    $newDate strtotime($newsDate);

    // d M Y should be replaced with the format used by your $newsDate
    $newDateFormatted date('d M Y'$newDate);

    // ugh, I'm used to java so without a compareto I will attempt an exact equals instead:
    if ($newDateFormatted === $newsDate)
    {
        echo 
    "The date is correctly formatted\n";
    }
    else
    {
        echo 
    "The date is not correctly formatted\n";
    }
    ?>
    The formatting should match your original, all this script does is take the current, attempt to parse the format into a timestamp, format the new timestamp back into its original format and compare them. As my comment mentions, I'm not 100% certain if the === operator will work with strings, so you may want to simply output the original format with the new format to visually compare them instead. As well, depending on your php version, $newDateFormatted could be a null value, which will throw you some errors.
    If it appears to work correctly, you can use the same concept to write the timestamp and update your database.

    Let me know if you've got any troubles.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New Coder
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    91
    Thanks
    21
    Thanked 0 Times in 0 Posts
    You will need to update the posts as well.
    But that's exactly what I wanted to know, if it is possible without updating the existing posts? This will require a lot of coding which I do not wish to do. I simply want to alter the date format in the database, and if I do so, the date format for every existing post will be altered aswell. I though it wasn't possible, and I think you will be telling me the same next :P

    Many thanks for your help so far, it's greatly appreciated!

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Read this article by Guelphdad on how to convert a database field to date or datetime type. It is well worth the effort to do so.

    After you do that you may need to make adjustments to how PHP treats the data coming from that field, but again, well worth the effort looking into the future.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •