Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date to day name e.g. Mon, Tue, Wed

Tags:

php

I have a variable that outputs the date in the following format:

201308131830 

Which is 2013 - Aug - 13 - 18:30

I am using this to retrieve the day name but it is getting the wrong days:

$dayname = date('D', strtotime($longdate)); 

Any idea what I am doing wrong?

like image 670
user1444027 Avatar asked Mar 13 '13 14:03

user1444027


People also ask

How do I convert a date to a day name in Excel?

Go to the Number tab in the Format Cells dialog box. Select Custom as the Category. Add dddd into the Type field for the full weekday name or ddd for the abbreviated weekday name. Press the OK button.

How do I find the day name from a date?

The DAY function takes just one argument, the date from which you want to extract the day. In the example, the formula is: = DAY ( B5 ) B5 contains a date value for January 5, 2016. The DAY function returns the number 5 representing the day...

How do I convert a date to a day of the week in Excel?

In a blank cell, please enter the formula =CHOOSE(WEEKDAY(B1),"Sun","Mon","Tue","Wed","Thu","Fri","Sat"), and press the Enter key. This formula will convert the date to the day of week as below screenshot shown.


1 Answers

This is what happens when you store your dates and times in a non-standard format. Working with them become problematic.

$datetime = DateTime::createFromFormat('YmdHi', '201308131830'); echo $datetime->format('D'); 

See it in action

like image 126
John Conde Avatar answered Sep 23 '22 02:09

John Conde