npsari Posted May 17, 2012 Share Posted May 17, 2012 Hello. Can you tell how to obtain the Day from the Date My Date format is as follows: Y-m-d I created a code, but it gives me the year... $date = date("Y-m-d"); $get_day = strtok($date, "-"); print"$get_day"; Programming is not my skill Quote Link to comment https://forums.phpfreaks.com/topic/262682-get-day-from-date/ Share on other sites More sharing options...
mrMarcus Posted May 17, 2012 Share Posted May 17, 2012 For starters: $date = date('d'); // equals the current day $day = end(explode('-', $date)); // also returns the day from a stored variable in that format Quote Link to comment https://forums.phpfreaks.com/topic/262682-get-day-from-date/#findComment-1346367 Share on other sites More sharing options...
scootstah Posted May 17, 2012 Share Posted May 17, 2012 All you need to do is call date with just the day. echo date('d'); If you have a date string like 2008-12-30, you can first convert it to a UNIX timestamp and then you're free to use the date function. $date = '2008-12-30'; // convert to UNIX timestamp $timestamp = strtotime($date); echo date('d', $timestamp); Also, if you are getting this date from a MySQL database, you can optionally format it in the query instead. Quote Link to comment https://forums.phpfreaks.com/topic/262682-get-day-from-date/#findComment-1346369 Share on other sites More sharing options...
npsari Posted May 17, 2012 Author Share Posted May 17, 2012 Thank you both Quote Link to comment https://forums.phpfreaks.com/topic/262682-get-day-from-date/#findComment-1346371 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.