ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Change DEFAULT date field format

October 27, 2011 12:03pm

Subscribe [3]
  • #1 / Oct 27, 2011 12:03pm

    DocDiversity

    14 posts

    I need to change the DEFAULT format of the Date Field to the same format the current_time variable has.

    This is the unchanged output right now:
    date: 2011-10-01 17:14
    current_time: 1319730267

    My aim is to use operators to compare these values to determine whether a relationship is “gone off” or “still on”. And: No :-( I can’t use

    {current_time format="%Y-%m-%d %G:%i"}

    because it all takes place in a matrix-field search-request.

    Here’s a link to the related thread in Brandon’s P&T Forum: http://help.pixelandtonic.com/brandonkelly/topics/matrix_complex_search_comparing_dates?utm_content=reply_link&utm_medium=email&utm_source=reply_notification#reply_7012094

    I’d appreciate your help very much!

  • #2 / Oct 28, 2011 12:46am

    John Henry Donovan

    12339 posts

    Hi DocDiversity,

    We don’t offer support for third-party addons unfortunately but Brandon looks like he has come back with a pretty good question for you if you wish to carry on the conversation over there

  • #3 / Oct 28, 2011 4:45am

    DocDiversity

    14 posts

    Hi John, thanks for the reply! I’m actually not sure if it’s a third party or first party question. EE outputs the current_time (Unix format) and the date field (%Y-%m-%d %G:%i) in those two different formats. I find that a bit odd. Should it be that way?
    If so, I guess every AddOn attempting to use that data might have trouble, right?

  • #4 / Oct 29, 2011 8:25am

    Mark Bowen

    12637 posts

    Hi DocDiversity,

    I see on that linked thread that you said you are using the Date Field and it is storing dates as a human readable string?

    Where are you seeing this exactly?

    Really all dates should be stored in ExpressionEngine as Unix time and I’ve not come across a developer that doesn’t do this yet so I’m just wondering where it is that you are seeing this human readable string?

    ExpressionEngine stores all dates in UNIX format so I don’t believe this can be an issue with ExpressionEngine but rather some 3rd party add-on or perhaps a fieldtype that you have installed here?

    Is that a possibility maybe?

    Does that help at all?

    Thanks,

    Mark

  • #5 / Nov 01, 2011 2:43pm

    DocDiversity

    14 posts

    Hi Mark,

    thank’s for taking the time to answer anyway!

    The field I’m talking about lives within a matrix field. It’s a normal native EE datefield format. Unfortunately I don’t have a clue how and where to look in the database to find out what actually is stored for that field there. Is there any “Guide” or Screencast about that you know of? I’d be glad to learn 😊

    I’m sure, it’s possible the problem could be caused by a third party add on. The only thing that comes to my mind here is the “Solspace Calendar” AddOn. But as far as I know the add on doesn’t change the way the normal date fields store the data. Haven’t heard about it and haven’t found any clues towards this in their forum.

    Cheers 😊

  • #6 / Nov 03, 2011 3:33pm

    Robin Sowell

    13255 posts

    Ah- see in the matrix thread you found them in the db- and they are stored as unix ts.  Which is how they should be.  Nor is a date variable with no formatting applied showing on the frontend in human readable form for me.

    I think I’m a little fuzzy on what you’re trying to do.  Is this comparison in a template?  And if so- do you have some simplified code?  And it may well be something that’s matrix specific and you’ll get a faster answer there.  But in truth, I’m not totally sure of what’s being compared where.

  • #7 / Nov 04, 2011 6:30am

    DocDiversity

    14 posts

    Hey Robin, hey Mark, hey John,

    it’s very likely you all got it right: it is a third party thing. Brandon from P&T pointed me to the respective table in the database where the matrix data is stored. In fact all dates from the date fields (real native EE date formats) are stored in UNIX time format there.

    Still, I’d like to explain what I’m trying to achieve with the code. I use Matrix fields to store three things per column:
    1. A relationship to another article via Playa field.
    2. a date_from (the date the relationship = teaser/ad is output on the website)
    3. a date_to (the date the relationship = teaser/ad disappears from the website output again).

    This way the editor has full control over teaser/ad planning and can use the matrix field to plan well ahead.

    There is two conditions I’m checking for per date column:
    a) is the date_from/date_to column empty (this should mean: “the teaser is valid endlessly”)
    b) is the date_from “smaller” than the current_time/is the date_to “bigger” than the current_time (in this case a specific start-date/end-date for the teaser is set)

    Thing is: a) works, b) works, but only solemnly :-(

    Here is some sample code ...

    Works:

    {my_matrix_field
      search:date_from=""
      search:date_to="" limit="3"}
    {teaser}
    {/my_matrix_field}

    Works:

    {my_matrix_field
      search:date_from="<={current_time}"
      search:date_to=">={current_time}"}
    {teaser}
    {/my_matrix_field}

    Worksn’t 😉 :

    {my_matrix_field
      search:date_from="|<={current_time}"
      search:date_to="|>={current_time}"}
    {teaser}
    {/my_matrix_field}

    Doesn’t work either:

    {my_matrix_field
      search:date_from="<={current_time|}"
      search:date_to=">={current_time}|"}
    {teaser}
    {/my_matrix_field}

    Doesn’t work either:

    {my_matrix_field
      search:date_from="<={current_time}|IS_EMPTY"
      search:date_to=">={current_time}|IS_EMPTY"}
    {teaser}
    {/my_matrix_field}

    Doesn’t work either:

    {my_matrix_field
      search:date_from="IS_EMPTY|<={current_time}"
      search:date_to="IS_EMPTY|>={current_time}"}
    {teaser}
    {/my_matrix_field}

     

  • #8 / Nov 04, 2011 12:01pm

    DocDiversity

    14 posts

    Whooohooo! Now there’s a solution:

    The “Empty” date field is stored as “0” in the database. That means THIS the code:

    {my_matrix_field
      search:date_from="<={current_time}|0"
      search:date_to=">={current_time}|0"}

    My gratitude to everyone who took part in this discussion 😊

  • #9 / Nov 04, 2011 12:42pm

    Robin Sowell

    13255 posts

    AHA!  And I would have never figured that out w/out going in and looking at your db.  Should have, though.  Thanks for figuring it out and sharing it- cause someone else will ask about this in the future!

    Glad you figured it out!  I just now groked what that search was doing.  Heh.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases