|
Posted by The Natural Philosopher on May 14, 2009, 4:26 am
Please log in for more thread options
=C1lvaro G. Vicario wrote:
show/hide quoted text
> JackM escribi=F3:
>> =C1lvaro G. Vicario wrote:
>>> JackM escribi=F3:
>>>> I need a little direction in manipulating a date being pulled from a=
=20
show/hide quoted text
>>>> mySQL db. It's not something I usually need to do so I am at a loss =
show/hide quoted text
>>>> on how to accomplish it.
>>>> The date is stored in the yyyy-mm-dd format in a field named dt that=
=20
show/hide quoted text
>>>> is of the date type. Some of the entries are entered as 1970-00-00=20
>>>> or 1970-05-00 where an actual month and/or day are unknown. I am=20
>>>> trying to manipulate those dates to drop the zeros and only print=20
>>>> out the year.
>>> A little hint:
>>> SELECT
>>> '2009-05-00',
>>> YEAR('2009-05-00'),
>>> MONTH('2009-05-00'),
>>> DAY('2009-05-00'),
>>> IF(DAY('2009-05-00')=3D0, YEAR('2009-05-00'), '2009-05-00')
>> Are you saying that I need to run a second SELECT statement for just=20
>> the date manipulation? I won't have the exact 2009-05-00 information=20
>> to do that with each entry.
>=20
> Nope. I'm suggesting that one of the possibilities is fetching the data=
=20
show/hide quoted text
> you need in the first place, rather than using a different format and=20
> then transform it. My code was a sampler of some MySQL functions that=20
> could help. Is it a strange approach?
>=20
>=20
Indeed.One might argue that Mysql is likely to be faster (being=20
compiled) than php at sorting data out..as well as ultimately being able =
to survive a possible internal format change on upgrade, better..
|
|
Posted by Jerry Stuckle on May 14, 2009, 6:34 am
Please log in for more thread options
Álvaro G. Vicario wrote:
show/hide quoted text
> JackM escribió:
>> Álvaro G. Vicario wrote:
>>> JackM escribió:
>>>> I need a little direction in manipulating a date being pulled from a
>>>> mySQL db. It's not something I usually need to do so I am at a loss
>>>> on how to accomplish it.
>>>> The date is stored in the yyyy-mm-dd format in a field named dt that
>>>> is of the date type. Some of the entries are entered as 1970-00-00
>>>> or 1970-05-00 where an actual month and/or day are unknown. I am
>>>> trying to manipulate those dates to drop the zeros and only print
>>>> out the year.
>>> A little hint:
>>> SELECT
>>> '2009-05-00',
>>> YEAR('2009-05-00'),
>>> MONTH('2009-05-00'),
>>> DAY('2009-05-00'),
>>> IF(DAY('2009-05-00')=0, YEAR('2009-05-00'), '2009-05-00')
>> Are you saying that I need to run a second SELECT statement for just
>> the date manipulation? I won't have the exact 2009-05-00 information
>> to do that with each entry.
>
> Nope. I'm suggesting that one of the possibilities is fetching the data
> you need in the first place, rather than using a different format and
> then transform it. My code was a sampler of some MySQL functions that
> could help. Is it a strange approach?
>
>
In this case I think it is, because this would call several additional
functions. Additionally, it doesn't do what he needs - it doesn't
return the year and month when only the day is 00. That could be done,
but it's even more work.
I think that a simple explode() and test would be much better here.
It's also easier to understand.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|
|
Posted by Jerry Stuckle on May 13, 2009, 2:48 pm
Please log in for more thread options JackM wrote:
show/hide quoted text
> I need a little direction in manipulating a date being pulled from a
> mySQL db. It's not something I usually need to do so I am at a loss on
> how to accomplish it.
>
> The date is stored in the yyyy-mm-dd format in a field named dt that is
> of the date type. Some of the entries are entered as 1970-00-00 or
> 1970-05-00 where an actual month and/or day are unknown. I am trying to
> manipulate those dates to drop the zeros and only print out the year.
>
> I am using $title1 = date('Y F d', strtotime($row["dt"])); to get the
> info from the db and it generally works fine when all three parameters
> are anything but zeros. I am using that because some of the dates are
> pre-1970.
>
> I have tried exploding an array:
>
> $arrayData = explode(" ", trim($title1));
> if (strcmp('00', $arrayData[1])){ //skip if arr[1] is 00
> if (strcmp('', $arrayData[1])) {
> $title1 = date('Y', strtotime($row["dt"]));
> }
> }
>
> but it didn't work. It strips all of the month/days out. Then I tried:
>
> if $title1(date('F')) == 00 {
> $title1(date('F')) = "";
> }
> if $title1(date('d')) == 00 {
> $title1(date('d')) = "";
> }
>
> and that didn't work either. Some of the dates that are in the db as
> 1971-00-00 or 1968-00-00 are coming out as November 30. Ugh.
>
> Can anyone point me in the right direction to do this? Thanks.
You should have gotten an E_NOTICE about $arrayData[1] not existing.
This is because the separator in your explode should be '-', not " ".
Additionally, your tests are incorrect - $arrayData[1] cannot be both
'00' and '', so your echo statement will never execute.
Also, you already have the year in $arrayData[1], why not just echo it
instead of calling the date function?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|
|
Posted by JackM on May 13, 2009, 3:58 pm
Please log in for more thread options Jerry Stuckle wrote:
show/hide quoted text
> JackM wrote:
>> I need a little direction in manipulating a date being pulled from a
>> mySQL db. It's not something I usually need to do so I am at a loss on
>> how to accomplish it.
>> The date is stored in the yyyy-mm-dd format in a field named dt that
>> is of the date type. Some of the entries are entered as 1970-00-00 or
>> 1970-05-00 where an actual month and/or day are unknown. I am trying
>> to manipulate those dates to drop the zeros and only print out the year.
>> I am using $title1 = date('Y F d', strtotime($row["dt"])); to get the
>> info from the db and it generally works fine when all three parameters
>> are anything but zeros. I am using that because some of the dates are
>> pre-1970.
>> I have tried exploding an array:
>> $arrayData = explode(" ", trim($title1));
>> if (strcmp('00', $arrayData[1])){ //skip if arr[1] is 00
>> if (strcmp('', $arrayData[1])) {
>> $title1 = date('Y', strtotime($row["dt"]));
>> }
>> }
>> but it didn't work. It strips all of the month/days out. Then I tried:
>> if $title1(date('F')) == 00 {
>> $title1(date('F')) = "";
>> }
>> if $title1(date('d')) == 00 {
>> $title1(date('d')) = "";
>> }
>> and that didn't work either. Some of the dates that are in the db as
>> 1971-00-00 or 1968-00-00 are coming out as November 30. Ugh.
>> Can anyone point me in the right direction to do this? Thanks.
>
> You should have gotten an E_NOTICE about $arrayData[1] not existing.
> This is because the separator in your explode should be '-', not " ".
>
> Additionally, your tests are incorrect - $arrayData[1] cannot be both
> '00' and '', so your echo statement will never execute.
>
> Also, you already have the year in $arrayData[1], why not just echo it
> instead of calling the date function?
Jerry, as I mentioned above, I'm using
$title1 = date('Y F d', strtotime($row["dt"]));
to get the data. That has already removed the "-" separator that is in
the db field. So my delimiter is in fact a space. Confirmed by echoing
the variable. Ergo, no error. The $title1 variable has the year, month
and day as in 1970 May 05 already in it. So I was counting 1970 as
$arrayData[0], May as $arrayData[1] and 05 as $arrayData[2]. I want to
check only 1 and 2 for the double 00 and only print the year (if both
month/day are 00) or the year and month (if day is 00) from the
$arrayData if it is found. That's my goal.
I will try what you suggest: echo the $arrayData[1].
|
| Similar Threads | Posted | | Help with comparing date stamp in PHP to date AND time stamp coming from MYSQL db!!!!!! | May 8, 2008, 1:21 am |
| displaying a pdf coming out of a mysql-db in a frame | October 8, 2004, 12:31 pm |
| Date is not being pulled from MYSQL database, instead current date is displayed!!! | March 22, 2006, 12:29 pm |
| Put today's date into a MySQL "date" formated field | August 3, 2006, 3:47 pm |
| manipulating forms | December 12, 2006, 9:07 pm |
| Manipulating binary data | April 29, 2007, 12:36 pm |
| manipulating multiple browser windows | September 9, 2004, 4:44 pm |
| reading and manipulating vcalendar files | June 12, 2005, 8:00 am |
| Manipulating an object returned from function | July 13, 2007, 12:11 pm |
| POST variables not coming through | August 29, 2006, 11:33 am |
|
>> =C1lvaro G. Vicario wrote:
>>> JackM escribi=F3:
>>>> I need a little direction in manipulating a date being pulled from a=