tag:blogger.com,1999:blog-30379699.post5800470648360593550..comments2023-02-20T16:25:34.686+00:00Comments on Caroline Mockett: A Stitch In TimeCaz Mocketthttp://www.blogger.com/profile/10460489611014669888noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-30379699.post-58156950394115813272007-10-11T09:55:00.000+00:002007-10-11T09:55:00.000+00:00Hi Caz!I am a web designer myself located in South...Hi Caz!<BR/><BR/>I am a <A HREF="http://www.sawebsitedesigner.co.za" REL="nofollow">web designer</A> myself located in South Africa but as of yet have not started programming in PHp and MYSQL. Can you suggest a good book to start of with?<BR/><BR/>Nice blog by the way.Anashttps://www.blogger.com/profile/07751560243666563204noreply@blogger.comtag:blogger.com,1999:blog-30379699.post-74004977870245786012007-08-29T17:10:00.000+00:002007-08-29T17:10:00.000+00:00While dates should indeed be stored as DATE, I don...While dates should indeed be stored as DATE, I don't think this *is* a date - it's a more complex datatype which can't be expressed in native SQL (you'd need an equivalent of union typing or something).<BR/><BR/>By the way, rather than all the print_r() invocations, I'd be inclined to:<BR/><BR/>(a) have a stringify function for your magical data type (useful for logging, if you ever need to email, etc.)<BR/><BR/>(b) convert your textual type that comes out of the database into a PHP struct, or better an object that knows how to format itself -- (a) then becomes a method<BR/><BR/>(c) use PHP date formatting functions so that localisation isn't such a pain<BR/><BR/>- JJames Ayletthttps://www.blogger.com/profile/15086298091974084361noreply@blogger.comtag:blogger.com,1999:blog-30379699.post-15531822071957673692007-08-29T14:32:00.000+00:002007-08-29T14:32:00.000+00:00Guys, Whilst I see what you are saying with the da...Guys, <BR/><BR/>Whilst I see what you are saying with the date formatting (and padding), it still doesn't really solve my dilemma. Even if (some) dates get padded with extra day/month info, others will have the correct thing stored, and so the application won't "know" which portion of the date to take as true - it's an all or nothing solution.<BR/><BR/>I can't perceive any need for adding dates togeather, since it was just a method of indicating when something was published. For articles in the newspaper, it needs to be specified to day level, journals are often just month/year and books are only specified as year of publication.<BR/><BR/>I wonder if I can put the lid back on the can of worms or not...!<BR/><BR/>CazCaz Mocketthttps://www.blogger.com/profile/10460489611014669888noreply@blogger.comtag:blogger.com,1999:blog-30379699.post-86865520478547130792007-08-29T14:01:00.000+00:002007-08-29T14:01:00.000+00:00I appreciate this might not be particularly helpfu...I appreciate this might not be particularly helpful right now, but in my experience it's always best to store dates as a date-specific field (whether that's a timestamp or a date) regardless of the level of precision you intend to use. Pretty much as Ross says; if you set it to January 1st YYYY at 00:00:00 then those additional specifics are there waiting to be set as and when you need them. Until that point, you can just use the year part without problems. Also, using this format can help get around problems with US vs UK date formats when you start adding days and months.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-30379699.post-17037815465225557382007-08-29T13:53:00.000+00:002007-08-29T13:53:00.000+00:00Sorry Caz - have re-read my comment and while it m...Sorry Caz - have re-read my comment and while it made sense in my head that is indeed a magical place!<BR/><BR/>Attempt 2:<BR/><BR/>Store your dates as a datefield, or a timestamp field.<BR/><BR/>Have some PHP logic that will pad out the dates as required (so that 2000 would actually be added into the database as 1st January 2000) and so on.<BR/><BR/>You can use my previous comment to format your dates as required.<BR/>AND<BR/>Things should sort as required!?!<BR/><BR/>If they want things to sort better tell them to be more specific ;>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-30379699.post-2697467662931192672007-08-29T13:32:00.000+00:002007-08-29T13:32:00.000+00:00Ross, thanks for the suggestion, but as you can se...Ross, thanks for the suggestion, but as you can see, it doesn't parse the right "date" if the date/month aren't supplied. Gah!Caz Mocketthttps://www.blogger.com/profile/10460489611014669888noreply@blogger.comtag:blogger.com,1999:blog-30379699.post-33874555102641158962007-08-29T13:12:00.000+00:002007-08-29T13:12:00.000+00:00You could go for an "elegant hack" that will enter...You could go for an "elegant hack" that will enter 1st Jan YYYY when that is just entered or 1st MM YYYY when they do both a month and year.<BR/><BR/>Human readable dates can be done with a combination of the strtotome and date functions - so for instance:<BR/><BR/>date('whatever options you want to show, strtotime($['dateFromDB'])');<BR/><BR/>Any good?!?!Anonymousnoreply@blogger.com