Jump to content

Get Day from Date


npsari

Recommended Posts

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  :shrug:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.