The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Getting day of week out of datestamp
Discuss Getting day of week out of datestamp in the PHP Development forum on Dev Shed. Getting day of week out of datestamp PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 30th, 2000, 08:33 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
I currently have a datestamp in the format yyyymmdd. I want to pull the day of the week (Monday, Tuesday, etc...) out of that datestamp at any given time.
Currently my code looks like this:
$datearray = getdate($firstdatestamp);
echo $datearray["weekday"];
When $firstdatestamp = 20000501 (or the first of May, 2000) the weekday returned is Thursday when really it should be Monday!
I tried:
echo date("l", time());
and it gives me the right weekday but only for the current date. I need to pass this my datestamp and am not too sure how.
Please help!!!!!
Thanks,
Stephanie Lemaire
|

May 30th, 2000, 03:50 PM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
Are you pulling this from a database? If so, many db engines have date functions that'll do that.
|

May 31st, 2000, 07:24 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Yes actually, my data is coming from a MySQL database.
I did figure out the reason it wasn't working was because my datestamp wasn't in proper UNIX format, so I develop a new datestamp out of the old one and process that.
A cleaner way would be nice though
Thanks,
Stephanie
|

May 31st, 2000, 04:08 PM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
select dayname(date_field_name) as dayname from table;
|

May 31st, 2000, 06:16 PM
|
|
Junior Member
|
|
Join Date: May 2000
Posts: 15
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
I would put the date into a unix timestamp when you pull it from the database. That way you can use the date function on it at any time to manipulate into the format you would like whether it be day of the week or whatever.
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
$result = mysql_query("SELECT UNIX_TIMESTAMP(my_date_field) FROM my_table");
$row = mysql_fetch_array($result);
$my_unix_date = $row["UNIX_TIMESTAMP"];
$day_of_week = date("l", $my_unix_date);
[/code]
|

June 2nd, 2000, 02:52 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Dear Stephanie,
If you want to pull day of the week out in any given time you can use built-in function from MySQL, ex:
SELECT dayname("20000602");
return value:
+---------------------+
| dayname("20000602") |
+---------------------+
| Friday |
+---------------------+
best regards,
Tata
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|