Re: [PHP] Reverse of date(w)
On Mon, September 18, 2006 5:09 pm, Kevin Murphy wrote: I'm looking for something that will convert a the opposite of the date (w) function. In other words, if I have the number 3, I would like it to return Wednesday. Is there such a beast out there besides writing a switch or array or something? I always just put: $daynames = array_flip(array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')); in my globals include file or whatever and use that... [shrug] -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reverse of date(w)
Kevin Murphy wrote: Not really. If it were always today that would work, but in this case, I was thinking of storing a day of the week in a database (3), and then display the info based on that digit. So assuming that the number was in fact 3, then: echo date(D,3); Would return Wed. Is there any function like that? Oh, and it has to run on PHP 4. Any reason you wouldn't write it yourself? ?php function getDayFromInteger($integer) { $days = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); if (isset($days[$integer])) { return $days[$integer]; } return false; } ? No reason. and its what I was planning on. I just was hoping that there was a pre-built function that I was just not seeing. Your solution above is probably the best one. Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Reverse of date(w)
I'm looking for something that will convert a the opposite of the date (w) function. In other words, if I have the number 3, I would like it to return Wednesday. Is there such a beast out there besides writing a switch or array or something? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
RE: [PHP] Reverse of date(w)
[snip] I'm looking for something that will convert a the opposite of the date (w) function. In other words, if I have the number 3, I would like it to return Wednesday. Is there such a beast out there besides writing a switch or array or something? [/snip] Perhaps http://www.php.net/idate -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reverse of date(w)
Not really. If it were always today that would work, but in this case, I was thinking of storing a day of the week in a database (3), and then display the info based on that digit. So assuming that the number was in fact 3, then: echo date(D,3); Would return Wed. Is there any function like that? Oh, and it has to run on PHP 4. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Sep 18, 2006, at 3:18 PM, Jay Blanchard wrote: [snip] I'm looking for something that will convert a the opposite of the date (w) function. In other words, if I have the number 3, I would like it to return Wednesday. Is there such a beast out there besides writing a switch or array or something? [/snip] Perhaps http://www.php.net/idate -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reverse of date(w)
Kevin Murphy wrote: Not really. If it were always today that would work, but in this case, I was thinking of storing a day of the week in a database (3), and then display the info based on that digit. So assuming that the number was in fact 3, then: echo date(D,3); Would return Wed. Is there any function like that? Oh, and it has to run on PHP 4. Any reason you wouldn't write it yourself? ?php function getDayFromInteger($integer) { $days = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); if (isset($days[$integer])) { return $days[$integer]; } return false; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reverse of date(w)
Another way to do it would be to store the unix epoch and then just get the weekday name from that? More overhead than Travis's idea, but just as good and you could possibly use the date/time later on. On 9/18/06, Travis Doherty [EMAIL PROTECTED] wrote: Kevin Murphy wrote: Not really. If it were always today that would work, but in this case, I was thinking of storing a day of the week in a database (3), and then display the info based on that digit. So assuming that the number was in fact 3, then: echo date(D,3); Would return Wed. Is there any function like that? Oh, and it has to run on PHP 4. Any reason you wouldn't write it yourself? ?php function getDayFromInteger($integer) { $days = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); if (isset($days[$integer])) { return $days[$integer]; } return false; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reverse of date(w)
Chris Ditty wrote: Another way to do it would be to store the unix epoch and then just get the weekday name from that? More overhead than Travis's idea, but just as good and you could possibly use the date/time later on. I use the DATETIME fieldtypes in MySQL, same idea... 100% agreed that keeping that timestamp for later use is a good idea. For Kevin's original question.. Here is the MySQL function to get that short weekday name off of a DATETIME column: Table with datetime column: mysql SELECT id,effectivetime - FROM event - WHERE employee_id ='1001'; +-+-+ | id | effectivetime | +-+-+ | 184 | 2006-09-18 18:50:25 | | 182 | 2006-09-17 23:12:17 | | 178 | 2006-09-12 21:59:44 | +-+-+ 3 rows in set (0.00 sec) Query to get 'weekday': mysql SELECT id,effectivetime,DATE_FORMAT(effectivetime,%a) AS weekday - FROM event - WHERE employee_id = '1001'; +-+-+-+ | id | effectivetime | weekday | +-+-+-+ | 184 | 2006-09-18 18:50:25 | Mon | | 182 | 2006-09-17 23:12:17 | Sun | | 178 | 2006-09-12 21:59:44 | Tue | +-+-+-+ 3 rows in set (0.00 sec) Those DATETIME columns can do some other neat things too: SELECT * FROM events WHERE starttime BETWEEN '2006-09-18' AND '2006-09-28' Gives me a list of events happening in a certain period... SELECT * FROM events WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) starttime Gets you the last 30 days without needing to make those '2006-09-18' style strings in PHP code. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html They should all work on DATETIME type columns, storing seconds since epoch doesn't quite give you that (you could work it in pretty easily I'm sure, why not use the native column type!) Cheers, Travis On 9/18/06, Travis Doherty [EMAIL PROTECTED] wrote: Kevin Murphy wrote: Not really. If it were always today that would work, but in this case, I was thinking of storing a day of the week in a database (3), and then display the info based on that digit. So assuming that the number was in fact 3, then: echo date(D,3); Would return Wed. Is there any function like that? Oh, and it has to run on PHP 4. Any reason you wouldn't write it yourself? ?php function getDayFromInteger($integer) { $days = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); if (isset($days[$integer])) { return $days[$integer]; } return false; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php