Change NewsPublisher Date Picker Format; Set Default Date to 'Today'

It appears that the date format of YYYY-MM-DD is hard-coded into newspublisher.class.php?

Is there a way to alter this (hopefully not by editing the php file itself)?
Format changes submitted via the Date tv that I’m bringing into the NewsPublisher template are ignored. The same is true for default date - what I’ve set via the TV are ignored by NewsPublisher.

I see no settings within the snippet for any of the above. Any advice on how to make these changes would be greatly appreciated!

It seems there is a lexicon entry np_date_format to set the date format. But the format is quite cryptic and the url in the code doesn’t work anymore (so you have to use

The default value from the TV only seems to work when you put a fix date like 2021-11-30 into it.
And it looks like the value from the &presets property gets overwritten for date TVs.

Maybe you can add a JS script to the page to add a default value, otherwise I suspect you have to change some PHP code.

Yah I saw the lexicon and found the defunct link – fantastic idea to use

Unfortunately, the aforementioned lexicon appears to govern separators (i.e. “-”, “/”, etc.) used in the date string and does not affect the timestamp.

In any event, editing the NP file is an impermanent solution, since any update would overwrite changes.

It’s obvious that a ton of work went into creating NP; I can only assume inflexibility around date / time TV output is a result of the need to focus elsewhere.

Bob, if you’re out there and can chime in with ideas, :pray: :pray:

That complicated code is the result of my trying to duplicate the date/time display in the manager, which splits the date and time with separate controls for each one. I’m afraid that makes it extremely difficult, if not impossible, to accomplish what you’re trying to do.

The only thing I can think of would be to write some JavaScript that gets the current date/time and manipulates the datepicker to select it. It would still be quite difficult.

You could try out this change to the code to see if it works to set a default value for the date.

Change this line

to this:

//Don't set placeholder if value is empty and a placeholder with the same name already exists
if (!(empty($s) && $this->modx->getPlaceholder($this->prefix . '.' . $name))){
    $this->modx->toPlaceholder($name, $s, $this->prefix);

Then use the &presets property in the call to NewsPublisher.


Thank you for the idea. Unfortunately, this change to the file and addition to the preset parameter does not affect the date time TV format.

This fix is just to enable you to set a default date (and not to change the format). Does that part work?

Maybe I’m misunderstanding what you are trying to achieve.

Screenshot 2021-12-02 at 21-40-20 Newspublisher Test - MODX Revolution

  • What do you want to see in the date field (on the left)?
  • What do you want to see in the time field (on the right)?
  • What is the value of [[++cultureKey]] on your site?
  • What is the lexicon value of np_date_format (for the language of your [[++cultureKey]])?

Sorry, let me clarify. Poor use of language on my part. Your code changes target what I’m after.

Prior to your suggestions, I’d attempted to provide a preset for my date tv (npEntryDate) as follows:

&presets=npEntryDate:[[!+nowdate:default=now:strtotime:date=%a %b %d %Y]]`

This output:
Screen Shot 2021-12-02 at 3.03.36 PM

This did not change after implementing the changes you suggested.

cultureKey value is en. Not sure where to find this for np_date_format.

So now I’m really confused. %a %b %d %Y gives me the string Fri Dec 03 2021. Why would you want this as a format to input a date?

Make sure that in your TV npEntryDate in the tab “Input Options” the field “Default Value” is empty.

In the top menu click the cog-wheel icon → “Lexicons”. Then select “Namespace:” = newspublisher and “Language:” = en.

According to your screenshot the value for “np_date_format” is Y-ds-m-ds-d. (This means the Year Y followed by a dash ds followed by the month m followed by a dash and the day d).

You can change that to something different like d-dt-m-dt-Y (for 03.12.2021) but then you have to change the format in the &presets property accordingly.