Zen Cart Logo
Forums / General Questions / How to call Today's Date?

How to call Today's Date?

Views: 675

Results 1 to 9 of 9
9 Dec 2015, 6:49 PM
#1
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

How to call Today's Date?

Hi,

The admin section of my ZC puts today's date in the menu bar at the top. Is there a way I could call that code in, say, a product page, EZ page, etc?

Here is what I am looking to do. I have a page that lists a bunch of equipment I buy. It does not change terribly often, only if I want to add something specific. However, I would like for a visitor to feel like the list is being maintained constantly, thus (in theory) will be more encouraged to reach out and to do so sooner rather than later.

Despite the fact that my list changes rarely, I am ALWAYS buying every item on the list. So the underlying facts are legit, I'm just trying to artificially inflate the sense of urgency a bit.

Thought being that if I have a current date on the page, the visitor might think:
"Oh wow! This list just went up, lucky me!"

Or better yet:
"Woah! They want what I have, I better call quick in case the list changes tomorrow!"

Anyway, does anybody know the code and/or how I could insert it into the html of a page?

Thanks!

9 Dec 2015, 7:18 PM
#2
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: How to call Today's Date?

For extra credit, what I'd really like is if that date remained static and only updated on, say, Mondays at 9am.

So the html might look like this...

+++++++++++++++

We Buy Medical Equipment

**LAST UPDATE: **Monday December 7, 2015 - 9am

The following is a list of hospital equipment we are currently seeking.
If you know of anyone selling, please contact us right away.

SURGERY TABLES

  • Amsco 2080L Electric Surgery Table
  • Mizuho OSI Jackson Table, Spinal Table
  • Steris 3080RC Surgery Table
  • Steris 3080RL OR Table
    WARMING CABINETS
  • Amsco M70WC-EL Warming Cabinet
  • Amsco M70WCE Tabletop Blanket Warmer
  • Amsco Warming Cabinet, Dual Chamber
  • Steris Amsco Warming Cabinet, tabletop

+++++++++++++++

If I simply provide today's date, the visitor will easily see through it. But if the date says Monday and the visitor looks on Wednesday, then the date is much more believable.

Calling the date seems very straight forward. But only calling Monday would need some additional logic.

Any thoughts?

9 Dec 2015, 7:45 PM
#3
lloyd_borrett avatar

lloyd_borrett

Zen Follower

Join Date:
Mar 2006
Location:
Rosebud, Victoria, Australia
Posts:
308
Plugin Contributions:
2

Re: How to call Today's Date?

You should be able to add some extra PHP code to do that.

Zen Cart 1.5.5e, PHP 5.3.29 MySQL 5.5.42

9 Dec 2015, 7:48 PM
#4
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: How to call Today's Date?

That's what I'm hoping!

Any chance you could point me in the right direction? :D

9 Dec 2015, 9:23 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,102
Plugin Contributions:
56

Re: How to call Today's Date?

The following will output the date, in the format you specified, for the past Monday:

echo date ('l F j, Y', strtotime ('last Monday'));
9 Dec 2015, 9:42 PM
#6
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,967
Plugin Contributions:
8

Re: How to call Today's Date?

plenty of options as to how to accomplish this task, although dealing with dates always gets a bit tricky...

assuming you know where you want to place this information in your template, i see a couple of choices:

1.) you could store the last time you updated the date in the DB, use that variable in your template and then create a cron job to update it once a week (probably not my favorite way to go)
2.) do it programatically as lloyd said using php.

i would refer to this page:

http://php.net/manual/en/function.date.php

taking a quick shot with no warranty as to its usefulness or appropriateness for your situation, i would try the following:

$day_of_week = date(w);  // numeric rep of day of week
if (($day_of_week) == 0) {$day_of_week = 7;}  // move sunday from 0 to 7
$display_date = date("D F j, Y ", mktime(0, 0, 0, date("m")  , date("d")-($day_of_week-1), date("Y"))) . '- 9:00 am';  //convert to always have monday

you could then use $display_date in your template.

hope that helps!

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

9 Dec 2015, 9:44 PM
#7
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: How to call Today's Date?

Thanks!

But... I can't seem to get it to work right. I tried to wrap it and paste it into source on a page. Maybe I was wrapping it wrong?

Can you show me how you would insert this?

9 Dec 2015, 9:46 PM
#8
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,967
Plugin Contributions:
8

Re: How to call Today's Date?

seems lat9 beat me to the punch... lat9's code much more elegant!

last Monday - who knew! thanks.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

9 Dec 2015, 9:46 PM
#9
feznizzle avatar

feznizzle

Totally Zenned

Join Date:
Apr 2010
Posts:
900
Plugin Contributions:
0

Re: How to call Today's Date?

Missed Carlwhat's post as I was posting! Thanks, I am processing what you just said...