Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

date - PHP day of week numeric to day of week text

This may be really easy but I can't find a PHP function to do this...

OK so

$dow_numeric = date('w');

gives the numeric day of the week 0-6 for Sunday to Saturday.

And

$dow_text = date('D');

gives the 3 letter abbreviation for the text day of the week (Sun, Mon, etc.)

Is there a function or easy way to use $dow_numeric to get $dow_text? If I have '0' as $dow_numeric, how can I make $dow_text = 'Sun'? Yes a switch statement could do the job, but I’m looking for a more elegant solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Bit of a hack, but:

$dow_text = date('D', strtotime("Sunday +{$dow_numeric} days"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...