Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Senior Member tekp's Avatar
    Join Date
    Jan 2004
    Location
    A small village near a small city near a small cit
    Posts
    918
    Member #
    4667
    Liked
    1 times
    I've got something in a database with a field called 'date'. This is a 'timestamp' field, as opposed to 'medium text' or whatever all of my others are. I did this with phpMyAdmin.

    When I try to make a date from it, like:

    Code:
    date("dS M Y",$row[0]);
    Where $row[0] is the timestamp, it churns out 'January 21st 2038'. I read around and found out this was the highest possible date for PCs at the moment? Or something... And I noticed when I put something not a number in a mktime() function, it gave me the highest possible value (i.e., 60 mins or 24 hrs etc).

    So I reckon I'm doing something wrong / passing the wrong variable / the wrong kind of timestamp to it and it's panicking and giving me the highest value for everything.

    Am I right? How do I fix this?

    Cheers.
    tekp :cheeky: tekponline.com

  2.  

  3. #2
    Senior Member
    Join Date
    Jul 2005
    Location
    S.Wales, UK
    Posts
    250
    Member #
    10742
    A timestamp field and a date field are not the same thing. Althought techically they are, they work differently.

    A timestamp field requires a timestamp which is a numeric interpretation of a date. A date field requires the input to be in a date format such as yyyy-mm-dd. Not the same thing from a higher level point of view.

    Change the field type to date (not timestamp and not date/time)

    Secondly 'date' is a reserved word and it's not a good idea to use that as a field name. It may give you coding problems later. Instead call it 'thedate' or something.
    Paul Creedy
    Visit my community site at: www.rhonddacynontaff.com
    My hosting: www.rcthosting.com
    My Content Management product: www.dynamiccontenteditor.com

  4. #3
    Senior Member tekp's Avatar
    Join Date
    Jan 2004
    Location
    A small village near a small city near a small cit
    Posts
    918
    Member #
    4667
    Liked
    1 times
    Ok cool thanks, I'll try that.

    Cheers :thumbsup:
    tekp :cheeky: tekponline.com

  5. #4
    Senior Member
    Join Date
    Jul 2005
    Location
    S.Wales, UK
    Posts
    250
    Member #
    10742
    No problem.

    Dates can be a right pain as there are different ways of using them. We all have our favourite ways. Here are mine:

    1. Use date format, not timestamp (unix coders may disagree with me on that).

    2. Always send a date to the database in the format yyyy-mm-dd NOT dd-mm-yyyy or mm-dd-yyyy, because depending on the type of database, and the county it's hosted in, and the user, date formats change. The only consistant way is yyyy-mm-dd to make sure the date goes in correctly.

    3. Make sure your field names are not reserved words. Field names like 'date', 'username', 'password', 'text' can cause headaches later.
    Paul Creedy
    Visit my community site at: www.rhonddacynontaff.com
    My hosting: www.rcthosting.com
    My Content Management product: www.dynamiccontenteditor.com

  6. #5
    Senior Member tekp's Avatar
    Join Date
    Jan 2004
    Location
    A small village near a small city near a small cit
    Posts
    918
    Member #
    4667
    Liked
    1 times
    I see.

    Right, I changed the type of field on the database to 'date', and all of the entries' dates changed to YYYY-MM-DD. When I tried to do the date("whatever",$row[0]) on it, it now comes up as the 1st of something 1970 (which I assume is the lower bound of all the possible dates).

    Argh!!

    What am I doing wrong?
    tekp :cheeky: tekponline.com

  7. #6
    Senior Member
    Join Date
    Jul 2005
    Location
    S.Wales, UK
    Posts
    250
    Member #
    10742
    If you already had a date in there it would be in timestamp format (because that's the original format you used). Converting the field type to date won't convert the existing values. Delete the existing value and then type the date back in there in the format yyyy-mm-dd.
    Paul Creedy
    Visit my community site at: www.rhonddacynontaff.com
    My hosting: www.rcthosting.com
    My Content Management product: www.dynamiccontenteditor.com

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    And, more importantly, you can't use the date function in PHP to convert a date like that, IIRC. I believe the date function only takes UNIX timestamps. It looks like you have to use strtotime first.

  9. #8
    Senior Member
    Join Date
    Jul 2005
    Location
    S.Wales, UK
    Posts
    250
    Member #
    10742
    Ah! I missed that in his code.

    If the date is being stored as a timestamp then date function is used to convert it to a regular date. If it's being stored as an actual date then the date needs to be converted to a string for it to be displayed.
    Paul Creedy
    Visit my community site at: www.rhonddacynontaff.com
    My hosting: www.rcthosting.com
    My Content Management product: www.dynamiccontenteditor.com

  10. #9
    Senior Member tekp's Avatar
    Join Date
    Jan 2004
    Location
    A small village near a small city near a small cit
    Posts
    918
    Member #
    4667
    Liked
    1 times
    Ah i see, i'll try that, thanks

    tekp :cheeky: tekponline.com

  11. #10
    Senior Member tekp's Avatar
    Join Date
    Jan 2004
    Location
    A small village near a small city near a small cit
    Posts
    918
    Member #
    4667
    Liked
    1 times
    Yep, that worked with strtotime().

    Thanks a lot
    tekp :cheeky: tekponline.com


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:52 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com