Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Now that I have DATE_FORMAT working, I'd like to chop up the date into parts...how is this done?

Guest
Oct 30, 2010 Oct 30, 2010

Copy link to clipboard

Copied

Hello All,

First off, many thanks to my friends Bregent and iPHP for helping me get my last problem sorted out, and fast.

Now, I have this query:

$sql = "SELECT page_ym, cal_dates, available, location, event,
        DATE_FORMAT(cal_dates, '%W %D') AS cdate
        FROM cal_data
        WHERE cal_data.page_ym = '$dateRef%'";

$result = $conn->query($sql) or die(mysqli_error());
$calSpec = $result->fetch_assoc();

and it works perfectly.

What I'd like to do is separate the weekday and date in the $calSpec['cdate'] string into two different items.

I have fiddled with the explode function but I don't think I'm doing it right. I'm assuming I'd explode the string, $calSpec['cdate'] and store its components in an array within the do while loop I have set up to populate the page with dates.

Is this the best approach? If so, can anyone steer me in the right direction with regards to proper explode syntax?

You are all amazing people, thank you in advance for your help!

Sincerely,

wordman

TOPICS
Server side applications

Views

361
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 30, 2010 Oct 30, 2010

Copy link to clipboard

Copied

$sql = "SELECT page_ym, cal_dates, available, location, event,

        DATE_FORMAT(cal_dates, '%W') AS weekday,

        DATE_FORMAT(cal_dates, '%D') AS the_date
        FROM cal_data
        WHERE cal_data.page_ym = '$dateRef%'";

$result = $conn->query($sql) or die(mysqli_error());
$calSpec = $result->fetch_assoc();

echo $calSpec['weekday'];

echo $calSpec['the_date'];

Format the weekday/date separately in the query.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 30, 2010 Oct 30, 2010

Copy link to clipboard

Copied

iPHP

Wow! You know, I tried a variation of that, which was a complete guess, and of course it was absolutely wrong.

I had no idea you could stack DATE_FORMAT one after the other! I researched this for a LONG time and nothing came up like what you suggested, so thank you for this! I hope that this thread helps others who are or will soon be in my shoes. This forum is the BEST!!!

And of course, it works like a charm. Thank you.

Many incredibly sincere thanks,

wordman

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 30, 2010 Oct 30, 2010

Copy link to clipboard

Copied

LATEST

ps - have any thoughts about the changing font/border color post i put up earlier?

thanks!!!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines