PHP, extracting the day name of a selected date?

  • MISC/A++
  • Expert
  • Expert
  • User avatar
  • Joined: Sep 08, 2004
  • Posts: 508
  • Loc: UnderGround
  • Status: Offline

Post October 30th, 2007, 6:05 pm

I use a javascript popup calendar which outputs the result into a textbox, the next step is to post to get the date selected.

For example, if i select 2007-11-05 from the calendar how can i find the day of the week?

For example 2007-11-05 is on Monday.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 30th, 2007, 6:05 pm

  • Nebulous
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Nov 20, 2004
  • Posts: 59
  • Loc: Hampshire, UK
  • Status: Offline

Post October 31st, 2007, 5:06 am

I haven't had the time, nor access to the facilities to test this at the moment, but from what I can see it should work without any problems...


PHP Code: [ Select ]
 
$date = '2007/10/31';
 
$weekday = date('l', strtotime($date)); // note: first arg to date() is lower-case L
 
echo $weekday; // SHOULD display Wednesday
 
 
  1.  
  2. $date = '2007/10/31';
  3.  
  4. $weekday = date('l', strtotime($date)); // note: first arg to date() is lower-case L
  5.  
  6. echo $weekday; // SHOULD display Wednesday
  7.  
  8.  


The script is not dependant on the input structure of the date, providing it is valid, so you can customize it to your needs.
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post October 31st, 2007, 6:14 pm

Nebulous wrote:
I haven't had the time, nor access to the facilities to test this at the moment, but from what I can see it should work without any problems...


PHP Code: [ Select ]
$date = '2007/10/31';
$weekday = date('l', strtotime($date)); // note: first arg to date() is lower-case L
echo $weekday; // SHOULD display Wednesday
 
  1. $date = '2007/10/31';
  2. $weekday = date('l', strtotime($date)); // note: first arg to date() is lower-case L
  3. echo $weekday; // SHOULD display Wednesday
  4.  


The script is not dependant on the input structure of the date, providing it is valid, so you can customize it to your needs.


That displays Wednesday for every date.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • MISC/A++
  • Expert
  • Expert
  • User avatar
  • Joined: Sep 08, 2004
  • Posts: 508
  • Loc: UnderGround
  • Status: Offline

Post November 1st, 2007, 1:57 am

PHP Code: [ Select ]
 
echo date('l', strtotim($date));
 
 
  1.  
  2. echo date('l', strtotim($date));
  3.  
  4.  


Thanks guys.
  • Abdullah62
  • Born
  • Born
  • No Avatar
  • Joined: May 26, 2010
  • Posts: 1
  • Status: Offline

Post May 26th, 2010, 1:41 pm

to all

guys thanks for your help.

I have faced the same problem and you have helped me

I want to edit to what you have wrote instead of using the method strtotim($date)) which change the string to date for those who use a date varible, they don't need to use the method strtotim(),just past the date variable alone

so the end result will be like this
echo date('l', $date));

now you will get the date names
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post May 26th, 2010, 2:18 pm

PHP Code: [ Select ]
<?php
 
// Create a new instance
$today = new DateTime('2015-11-05');
 
// Look a year into the future for example sake
$today->modify('+1 year 12 days');
 
// Display full day name
echo $today->format('l') . PHP_EOL; // lowercase L
 
// Display three-letter day name
echo $today->format('D') . PHP_EOL;
 
?>
  1. <?php
  2.  
  3. // Create a new instance
  4. $today = new DateTime('2015-11-05');
  5.  
  6. // Look a year into the future for example sake
  7. $today->modify('+1 year 12 days');
  8.  
  9. // Display full day name
  10. echo $today->format('l') . PHP_EOL; // lowercase L
  11.  
  12. // Display three-letter day name
  13. echo $today->format('D') . PHP_EOL;
  14.  
  15. ?>


Code: [ Select ]
joebert@frankenstien:~/Desktop$ php -f _.php
Thursday
Thu
joebert@frankenstien:~/Desktop$
  1. joebert@frankenstien:~/Desktop$ php -f _.php
  2. Thursday
  3. Thu
  4. joebert@frankenstien:~/Desktop$
Strong with this one, the sudo is.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 122 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.