Jump to content
xisto Community
Sign in to follow this  
ebbinger_413

Need Help With Php.... srry if this post is in wrong place.....

Recommended Posts

im just learning php right now and messing around a little with it...

 

but i have been trying to insert the date and time (which i already have the script to do so but just want to do it with my own script) into my page...but it isnt working and i believe i am doing sumtin majorly wrong...

 

this is what my page looks like...

 

<?php

//Prints something like: Monday

echo date("l");//

 

Prints something like: Monday 15th of January 2003 05:51:38 AM

echo date("l dS of F Y h:i:s A");

 

//Prints something like: Monday the 15th

echo date("l \\t\h\e jS");

?>

 

what is wrong with it ?...im confused...like i said i just started reading tutorials online and started writing some php...i suck at it...its the same way i learned html tho and i am good at html :P lol

 

anyways...yeah...

 

i also found this as well...

 

The Date() Function

 

The date() function is used to format a time or a date.

 

Syntax

string date (date_format[,int timestamp])

character - Description

 

 

a - "am" or "pm"

A- "AM" or "PM"

B - Swatch Internet time (000-999)

d - Day of the month with a leading zero (01-31)

D- Three characters that represents the day of the week (Mon-Sun)

F - The full name of the month (January-December)

g - The hour in 12-hour format without a leading zero (1-12)

G - The hour in 24-hour format without a leading zero (0-23)

h - The hour in 12-hour format with a leading zero (01-12)

H - The hour in 24-hour format with a leading zero (00-23)

i - The minutes with a leading zero (00-59)

I - "1" if the date is in daylights savings time, otherwise "0"

j - Day of the month without a leading zero (1-31)

l - The full name of the day (Monday-Sunday)

L- "1" if the year is a leap year, otherwise "0"

m - The month as a number, with a leading zero (01-12)

M- Three letters that represents the name of the month (Jan-Dec)

n - The month as a number without a leading zero (1-12)

O - The difference to Greenwich time (GMT) in hours

r - An RFC 822 formatted date (e.g. "Tue, 10 Apr 2005 18:34:07 +0300")

s - The seconds with a leading zero (00-59)

S - The English ordinal suffix for the day of the month (st, nd, rd or th)

t - The number of days in the given month (28-31)

T - The local time zone (e.g. "GMT")

U- The number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

w - The day of the week as a number (0-6, 0=Sunday)

W- ISO-8601 week number of year, weeks starting on Monday

Y - The year as a 4-digit number (e.g. 2003)

y- The year as a 2-digit number (e.g. 03)

z - The day of the year as a number (0-366)

 

(rry bout the table being *BLEEP* i was in a hurry) am i suppose to insert one of those into the script or sumtin...idk...im confused :S :P

Share this post


Link to post
Share on other sites

Don't put yourself down so much, we all had to begin somewhere.

A lot of my own PHP experience has been trial and error, though I do have a background in C/C++ as well as Perl but you still had to learn PHP as it's own language and not confuse it with the other general languages.

Try on a test (blank) page

<?phpecho date('l, j F Y'); // e.g.  Wednesday, 27 April 2005?>

What does your browser display?

You must realise too that the date format will be taken from the server it resides on, using it's time settings, it may not be neccessarily the same time zone as you, you may need to fix this too.

If this script works, then there's no problem other than it could result in an error which means turning on errors would be a good idea to see what problems exist.

Cheers,


MC

Share this post


Link to post
Share on other sites

maybe im just stupid or sumtin...but am i suppose to use an app to make php or can i just use notepad like i do with html....if so...frontpage wont work rightne ways...i put that string into notepad and saved it text.php....doesnt work...tried it with .html...nuttin....htm...nuttin....then i just inserted the php string into an old site of mine and it still didnt work so idk...yeah it is all just trial and error...thas how i was with html to...and now i am good at it...great thing tho about html is that it took me less than a week to learn it :P now i feel cool :P lol

Share this post


Link to post
Share on other sites
:D:P yo!!!!!! you can check the manual in php.net got my own question... how about detecting a STRING as a DATE??? do anyone knows???? data coming from database as string to be declared as a date???? i search over and over to different forums , php.net online resources but no one had tried answering my Q????? do anyone know about declaring string variables to be function as a date?? i want to :(:D detect a expiry date but since i cann't do this LOGIC if today is > expiry date then your account is expire

Share this post


Link to post
Share on other sites

OK, try this, just use notepad to do it

<?php echo 'Testing'; ?>

Save the page as "test.php" with the quotes and upload it to your server.

Then in your web browser type:

http://forums.xisto.com/no_longer_exists/

Does anything show? Is it asking to download, is it just showing the string <?php echo 'Testing'; ?> or in Firefox just ?>

Any chance of pointing us to your server it's on, to check whether it's PHP enabled or not.

It sounds like a misconfigured server if that doesn't work, or a server that doesn't have PHP.


Cheers,


MC

Share this post


Link to post
Share on other sites

Hey rvyne,

There's many ways to do this, not sure why you never got an answer, first of all, string dates should be in a valid unix date format, In your database you can convert date formats to a unix timestamp, you might want to look in your database's manual for a Date and Time section.

Here's an example:

<?php$today_timestamp = strtotime('now');$expiry1 = strtotime('10 May 2004'); // set expiry timestamp, using valid date format$expiry2 = strtotime('2005-05-02'); // set expiry timestamp, using another valid formatfunction check_expiry($today, $expired)  // function to check if expired{if($today > $expired) // if today is greater than expiry date{echo 'Has Expired'; // prints Has Expired}else{echo 'Still Valid';  // prints Still Valid}}check_expiry($today_timestamp, $expiry1);  // calls our first check using expiry1echo "<br />\n";check_expiry($today_timestamp, $expiry2);  // calls our second check using expiry2?>

I used two checks, just to show one that's expired and one that's not expired as well as showing you 2 different date formats we can use, but if you want to know more, then look up Unix Date Formats for more information. Functions in the PHP manual you may want to look at is strtotime which converts our string into a unix timestamp.

We should use timestamps in our comparisons as it's a numerical value, string comparisons can be done, but requires a lot more effort, since we got to check the string and match it with it's counterpart, e.g. day, month, year, then we've got to perform a check on each substring, it's easier if we are assigned numbers than strings.


Cheers,


MC

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.