To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Coding

Coding Help with PHP coding

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-07-2001, 06:11 AM   #1
neville
Senior Member
 
Join Date: Jan 2001
Posts: 108
date - weekdays

I am fetching week days from my db as numbers [0 for sunday and so on...]

How do I use the date function to get the weekday in full form, say, SUNDAY, MONDAY
by just feeding in numbers like 0,1 ?

Is there any other function to do the same ?

thanks.
neville is offline   Reply With Quote
Old 03-07-2001, 08:36 AM   #2
nando
Junior Member
 
Join Date: Jan 2001
Posts: 19
RE: date - weekdays

The PHP Manual explain how to manipulate date and time...

This is basic, but $weekday = date("l");

search phpmanual/ref.datetime.html
nando is offline   Reply With Quote
Old 03-07-2001, 11:38 AM   #3
reagent
Senior Member
 
Join Date: Feb 2001
Posts: 258
RE: date - weekdays

that will return the weekday for today, but we need the weekday name for whatever is in the db.

if you are using mysql, you could do
select unix_timestamp(date) as time_stamp
from <table>
where <conditions>

then use this
$result = mysql_query(...);
$row = mysql_fetch_array($result);
print date("l", $row["time_stamp"]);

another way would be to do it all in the query:

select date_format(date, '%W') as time_stamp
from <table>
where <conditions>

then use this
$result = mysql_query(...);
$row = mysql_fetch_array($result);
print $row["time_stamp"];

if you use the unix_timestamp method, that timestamp will be available to you if you wish to do different date formats of the same date..


good luck
reagent is offline   Reply With Quote
Old 03-07-2001, 02:37 PM   #4
Anon
Senior Member
 
Join Date: Jun 2000
Posts: 65,386
RE: date - weekdays

He seems to only have the numbers 0-6 available. I would just write my own conversion function.
Anon is offline   Reply With Quote
Old 03-07-2001, 05:31 PM   #5
reagent
Senior Member
 
Join Date: Feb 2001
Posts: 258
RE: date - weekdays

Thats fine if you just want to translate an integer into the weekday name, but he stated that the value was coming back from the database, I thought it would be easier and more efficient to use functions that already exist to do the same thing, rather than invent the wheel.

Again, that solution applied specifically to mysql, but there are similar functions in other RDBMS's

p.
reagent is offline   Reply With Quote
Old 03-08-2001, 01:21 AM   #6
neville
Senior Member
 
Join Date: Jan 2001
Posts: 108
RE: date - weekdays

All of these functions require that I have the date as one parameter .... but all I have are just numbers 0-6 which have to be printed as weekdays sun-sat on the page...
I can do it with a simple if-else but I want to use something inbuilt.

All php date functions require you to give some timestamp which means I have to split the date(which I don't have) in the mktime function ... same goes for all the mysql date functions that I checked out..... or did I miss any ?


Still looking for answers ......
neville is offline   Reply With Quote
Old 03-08-2001, 08:33 AM   #7
Anon
Senior Member
 
Join Date: Jun 2000
Posts: 65,386
RE: date - weekdays

ok, there is nothing "inbuilt" to do this. is the weekday in your table stored as just an integer? If so, you're right, this won't work. I had assumed that any date information in your DB would be stored as either date, datetime, or timestamp.

try using this

function getWeekday($iWeekdayId)
{
$arrWeekday = array(
[0] => "SUNDAY",
[1] => "MONDAY",
[2] => "TUESDAY",
[3] => "WEDNESDAY",
[4] => "THURSDAY",
[5] => "FRIDAY",
[6] => "SATURDAY"
);

return $arrWeekday[$iWeekdayId];
}

you may want to add in error checking to make sure that $iWeekdayId > 0 and <= 6

p.
Anon is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:41 PM.






Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.