Jump to content
#StayAtHome ×

Archived

This topic is now archived and is closed to further replies.

cowboysdude

Interesting.. but I could use your help..Please..

Recommended Posts

I am trying to change the date format that I get from MYSQL which is like this:

2008-05-05 20:28:22 and I want it like this: 5-5-2008 without the time.

 

I have been everywhere and tried everything but no luck...

here is what I have so far..

 

<?php

/**

* @version 1.0 $

* @package Euser

* @copyright © 2008 John Wade

* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL

*/

/** ensure this file is being included by a parent file */

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

include 'eopendb.php';

?>

 

<?php

 

global $my;

$thename = $my->username;

$theid =  $my->id;

$my_settings = "index.php?option=com_user&view=user&layout=form";

$my_link = "index.php?option=com_weblinks&view=weblink&layout=form";

$my_art = "index.php?option=com_content&view=article&layout=form";

$registerDate = $my->registerDate;

 

?>

 

<p>

<b>User Name:</b><font color="red"> <?php echo $thename;?></font><br>

<b>User Since:</b><font color="red"> <?php echo $registerDate;?></font><br>

<b>User Settings:</b><BR>

<a href="<?php echo $my_settings;?>">User Settings</a><br>

<a href="<?php echo $my_link;?>">Submit a Link</a><br>

<a href="<?php echo $my_art;?>">Submit News</a><br>

 

</font>

 

It does work but like I said it gives me the date format I don't want, what I want is just this: 5-5-2008 .. it's reading the mysql database but not putting it in the format I want.. like I said I've tried many things already... there has to be a simple way.. I'm probably over looking it... but then I'm not an expert either.. lol.

 

Many Thanks in advance!

 

Share this post


Link to post
Share on other sites

Try using something like this:

 

$string = "2008-05-05 20:28:22";

$date = date('d-m-Y',mktime(0,0,0,05,05,2008));

echo $date

 

This will display "05-05-2008".

 

The value for $string will need to be pulled in from the database.  Once you have the value, you'll need to parse it so you can plug in the correct values for mktime. (You didn't think I'd write ALL the code for you, did you?)

 

 

 

 

Share this post


Link to post
Share on other sites

OH no doubt that would work but all my users didn't register on that date.. lol

 

I'm pulling registerDate from the mysql database but can't seem to format it correctly...

 

That's what I'm trying to do.. use registerDate so it'll display the users register date in the 'm-d-Y' format.

 

I can display the registerdate for anyone but it's in the Y-d-m Time format...

 

see what i mean?

Share this post


Link to post
Share on other sites

Ok, so instead of using my $string, which was just an example, replace it with $registerDate.

 

Once you have your value ($registerDate), parse it using split, substr, or whatever so you have each value. So if $registerDate was '2008-02-05 20:28:22', you would want the following values:

 

$year = '2008';

$month = '05';

$day = '02';

 

Once you have the values, create the new date:

 

$date = date('m-d-Y',mktime(0,0,0,$day,$month,$year));

 

$date will now have the value '05-02-2008'. 

 

Share this post


Link to post
Share on other sites

Ok so it would look like this:

 

$registerDate = " ";

$date = date('d-m-Y',mktime(0,0,0,05,05,2008));

echo $date

 

Because I don't know what that date is until someone logs in... I can't use exact numbers... I'm pulling it from the table when a user logs in...

See what I mean?

 

The above just returns the date of 05-05-2008 for every user and that won't work... what happens if a user registered on 05-10-2008?

I don't know if I"m explaining this correctly.

 

I need to grab the $registerDate of the user who is logging in and display it in the m-d-Y format... whatever that date is and it will be different for each user...

Does that help?

 

Share this post


Link to post
Share on other sites

so if I do this...

 

<?php

$registerDate = $my->registerDate;

$date = "Select Format_Date('m-d-Y',$registerDate)";

echo $date

 

I get this:

 

Select Format_Date('m-d-Y',2008-05-05 20:28:22)

 

Which is the correct registerDate for THAT user only... but when I put like that it just prints out the above line...

How can I take the registerDate I asked for [no matter what that date is and it can be any date] and format it and print it out in m-d-Y format?

 

Thanks!!! You are a GREAT help!!

Share this post


Link to post
Share on other sites

$registerDate = $my->registerDate;  //this line is fine

 

Now you need to parse the date string to grab the day, month, and year values.  The following line will parse the year value:

 

$year = substr($registerDate,0,4); //this will give you '2008'

 

Now you need to parse the day and month.  Once you have the day ($day), month ($month), and year ($year) values, format them correctly by:

 

$date = date('d-m-Y',mktime(0,0,0,$month,$day,$year));

 

This will create a date value formatted like "mm-dd-yyy".

 

It doesn't matter what date is in $registerDate.  You may want to roll this code into a function where you pass $registerDate and it returns a date formatted correctly.

 

Btw, in your code, what is "Select Format_Date" referring to?  Is this supposed to be a function or maybe a sql statement?

Share this post


Link to post
Share on other sites

Interesting... this is the code...

 

<?php

$registerDate = $my->registerDate;

$year = substr($registerDate,0,4);

$date = date('d-m-Y',mktime(0,0,0,$month,$day,$year));

echo $date;

?>

 

This is the return -

 

Notice: Undefined variable: month in /hermes/bosweb/web099/b991/d5.johnw/public_html/modules/mod_euser/mod_euser.php on line 26

 

Notice: Undefined variable: day in /hermes/bosweb/web099/b991/d5.johnw/public_html/modules/mod_euser/mod_euser.php on line 26

30-11-2007

 

 

This is why I'm having a very difficult time with this.. I'm thinking I'm trying to do something easy but it's turning into anything but..lol

That's what I get when I use the above code...

Share this post


Link to post
Share on other sites

Are you even reading what I'm posting?

 

You're getting those errors because you haven't defined $month or $day.

 

See the third line where I define $year?  You need to do the same for $month and $day.   

 

You need to grab a substring of the date string ($registerDate) that contains the month value and a substring that contains the day value and assign them to the respective variables like I already did for $year.  Once you have these two values, along with the $year value, it will work.

 

Don't expect me to write all the code for you.  I'm leaving it up to you to figure out the substring for $month and $day.

Share this post


Link to post
Share on other sites

alrighty then... didn't expect you to write it for me.. just relaying info...

 

and by the way... you're not a teacher are you?

 

"Now you need to parse the day and month."  For someone who doesn't know, because if I did it would already be working this is greek. 

 

For Example;

$registerDate,0,4

How does one derive the year of 2008 from that?  what does 0,4 mean?  If you expect someone to do what you did, you should help them to understand what that means... then you can expect them to be able to 'finish' it.

 

by throwing examples out there assuming someone knows probably isn't the correct approach.  YES I am a teacher and I often look at a problem from this point of view.  IF someone is asking they do not understand therefore I'm going to help them understand not only the answer but how and why I got to the answer.  SO in the future that person or persons can solve a problem on their own.. It's not like I haven't tried to learn something here.. and everywhere else I've been it's that there is not much documentation as to HOW it works...

 

And to answer a previous question the "Select Format_Date" was a statement I've seen in other places and YES they don't explain it... so I tried it.  It didn't work, I've learned that... and no one died in the process.  Someone who is eager to learn is the best audience you can have.  Being short with them..well another story.  Do what you must .. and NO I didn't ask you to write it for me.  Explaining it would have helped greatly.

Share this post


Link to post
Share on other sites

My apologies on being a bit short...there are a lot of people out there that expect the code to be written for them...I try to push people in the right direction and let them figure out the rest.  I assumed you were familiar with PHP and some of the common commands/functions used in the language.

 

Ok...now that I know where you're coming from, let me explain a few more things...

 

substr($registerDate,0,4)

 

substr is a command in PHP that takes a substring from an existing string.  In this instance, $registerDate is the string, '0' is where you substring will start ('0' being the beginning of the string).  and '4' is the length of the string (4 characters).  You can read more about substr() at www.php.net/substr.

 

So when you see the following statement:

 

$year = substr($registerDate,0,4);

 

This takes a substring of the $registerDate variable starting at the beginning of the string and includes the first four characters ('2008' in my example).

 

To get the next variable, $day, you would use something like:

 

$day = substr($registerDate,5,2);

 

This would start at the sixth character (counting 0 as the first) and capture the next two characters, '05'.

 

$month = substr($registerDate,8,2) would grab the month value.

 

Once you have all three values, plug them in like so:

 

$date = date('d-m-Y',mktime(0,0,0,$month,$day,$year));

 

and you will have your formatted date.  You may want to read up on date() and mktime() as well so you have a better understanding of these commands.

Share this post


Link to post
Share on other sites

AW yes NOW that makes sense.. many Thanks!!!  Funny I did that and it worked!! YOU have been a great help and I appreciate it!!

 

sorry if I seemed testy but and this is MY fault I should have said I am no expert ... so at any rate with all your help YOU are finally the one who drove me to the right place... lol so to speak..

 

It's working perfectly... Thank you so much... this has been driving me nuts for over a week now...lol. 

 

I did look into the substr and figured it out... Now I'm gonna do some more reading and stop up at the bookstore and grab me a PHP book and 'educate' myself further.

 

Thank you again!!!

Share this post


Link to post
Share on other sites

WOW after re-reading your last post I must say that NOW it makes sense to me! You've made it clear as a bell and VERY easy to understand.  Here's what I was thinking... I was counting -> this way on the string to get the first number and then -> up the string again to get the second number.... Man... lol

 

OK now I count -> for the 1st number and the second number is the number of places... WOW that was to easy... sometimes I just can't believe I make this so hard.

 

OH my god.. Thank you!!

 

and YES I will read up on the other functions to better understand them.. excellent advice!

Share this post


Link to post
Share on other sites

Thanks for your help!!  This is the final result...

 

User Center

Date Today: 06-08-2008

User Since: 06-07-2008

Last Visit: 11-29-1999 [shows this because its the 1st visit, which is fine!  Tomorrow it will show 06-08-2008]

Real Name: Bob Smith

User Name: wayout

User Type: Registered

 

--= User Settings: =--

User Settings

Cancel Account

 

 

Thank you again!  YOU were awesome and the reason I FINALLY got this working!!!

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.