WordPress custom content type date field - wordpress

Hey, I'm trying to build the most intuitive possible Event post type. I'm wondering if there's a core method to both print out and capture the contents of a date field - specifically year/month/day, I don't need hours/minutes. I also need to be able to sort entries by date to print out later - for instance, I need all of the events from January. Something that can save me formatting the fields, and then parsing and saving them manually.
Any ideas are welcomed! Thanks in advance for your time.

There was no rock solid WP core solution to this, but the system I created is composed of:
SQL CONCAT to compare a date field to CURDATE, etc.
PHP strToTime to get the date back from the database
Generally speaking, if you save your date to the DB in UNIX time format it's easy to work with in SQL queries and in your PHP output.

Related

Can't Format Date in GraphQL in Gatsby Site

I am having trouble formatting a date in Gatsby. I have sourced some data from firestore. One of the fields that I have sourced is called datePublished and it contains a number in the form of a timestamp (e.g., 1576945502000). Indeed, it really is a timestamp, but it got saved to firestore in the number format type.
Now, I would like to format the datePublished field using the formatString function in graphql -- as noted here: https://www.gatsbyjs.org/docs/graphql-reference/#dates
But I can't get the formatting to work. Whether I try to format the string in graphiql or on my site, it does not work. Here is the code that I tried:
query MyQuery {
allNewsFeed {
edges {
node {
published(formatString:"dddd Mo, YYYY")
}
}
}
}
And this is the error message that I get in graphiql:
Unknown argument "formatString on field 'datePublished' of type 'NewsFeed'.
If I dig a little deeper, I notice that the field type in firestore is listed as number and in the graphiql document explorer it is listed as a FloatQueryOperatorInput.
What's more, I did a little experiment where I tried to save the same number as a string, number and timestamp in firestore. Neither the string or number format worked and for whatever reason, the gatsby-firesource plugin will not pull in the field with a timestamp format.
So I am wondering, what do I have to do to get this to work in gatsby?
Any ideas?
Thanks.
I had a similar situation with Gatsby not accepting "formatString" on a date field, for me what solved the issue was to change the format of the field to YYYY-MM-DD so it went from 02 06 2017 to 2017-06-02 and gatsby got the hint that that field represents a date.
It seems gatsby "reads" the data and guesses the type and based on that we get certain functionality.
Since gatsby uses moment.js I'm guessing the YYYY-MM-DD format is picked up by it.
I'm using MDX so it was really easy for me to change the format of my date field since it's just plain text, I'm not sure you have the same luxury with firestore but I hope this at least give you some ideas to try out. Good luck!

Powerapps - get stuck with UpdateContext

I am trying to build a PowerApp to log setup times of our machines by our fitters.
This is what my app looks like:
There are buttons named "Uhrzeit". Pressing these will write the current date and time into the Date/Time fields. I am using the following code:
UpdateContext({Total8:(Text( Now(); "[$-de-DE]dd/mm/yyyy hh:mm:ss" ))})
The Date/Time field is named Total8.
The code is working well but after saving the form and opening a new record the old data is still available in the fields. By clicking on the button "Zeiten zurücksetzen" I can "delete" the old data.
UpdateContext({Total8:""})
Problem: When I open one of the older records the old data is not available in the form. There is only the value of the last record. In the Common Data Service where my records are saved the values are correct.
As an example, I am saving this record:
When I open a new record, the values of the record 1 are still available. This should not be the case if my app worked properly.
For your Information:
If I enter the date/time without tapping the button, saving the record and opening a new record I don't have the problem. I think the "UpdateContext" code is not the code I should use here.
Can anyone help me solve the problem?
I don't think there's a problem with using the contexts in this way -- but remember that a context is just a variable. It isn't automatically linked to a datasource in any special way - so if you set it equal to Now(), it's going to keep that value until you do something different.
When you view an old record, you need to get the data from CDS and update your contexts to match the CDS data. Does this make sense?
Yeah thats my problem.
I want the variable to be linked to a datasource. Or is it possible to write the date/time into the fields without using a context variable?

SOLR Date range

I have to make an ezfind search page with date functions. For the SOLR filter I tried to use something like this: attr_publish_date_dt:[NOW-6MONTH TO NOW] but I don't get any result.
If I use it this way attr_publish_date_dt:[* TO NOW], it works. But all queries without an asterisk on the left hand don't work.
attr_publish_date_dt contains a unix timestamp so I also tried to use 2 timestamps from the attr_publish_date_dt:[* TO NOW] result, instead of [NOW-6MONTH TO NOW], but then I get also no results.
Can anyone help me please? Thanks in advance
Frank
Date searches are supported on a date field. You will need to define a field of that type, and submit dates in ISO-8601 format.
http://lucene.apache.org/solr/4_4_0/solr-core/org/apache/solr/schema/DateField.html
If you cannot properly format the timestamp before sending it to Solr, you may be able to use a DateFormatTransformer or a ScriptTransformer to do the job.
http://wiki.apache.org/solr/DataImportHandler#DateFormatTransformer
http://wiki.apache.org/solr/DataImportHandler#ScriptTransformer

Wordpress reverse date format for display but not db

I have a events page using a custom wp_query so that I can split post into upcoming events and past events. To do this I need the date to be stored in the database Y/m/d format but would like it to display on the front ends d/m/y. Any help on how I should do this, I could reverse it with jquery but there might be a better way?
thanks
That page is probably using the_date() function.
If so, modify it using format parameter to something like this:
the_date('d/m/Y');
Check also this Codex page about formatting the date and time.

create date formatted custom_meta field in wordpress admin

I have created a custom meta field to be used within a custom post type, that is to be the start time of a series of events. However, I would like to run my query_posts off of this value, but it is not formatted in date/time format, therefore '1:00pm' shows up in the list before '9:00am'. Is it possible to format this value in the db or at least prior to setting the 'meta_key' meta_value in my arguments for my query?
I've come across this problem a few times before. I'm going to use my most recent example because it sounds like it's along the same lines of what you're doing.
I had to create an event calendar using WordPress. In my custom post type, I had two fields: a start time and an end time. Instead of just using "1:00pm" as the start and end times, I also included the dates. This would allow for events that would last an entire weekend like a concert or a race.
What I'm getting at here, is once the user submitted that the event started on January 3, 2012 at 8:00 am and ended on January 3, 2012 at 10:00 am, I saved both of the variables using strtotime(). If you're not familiar with this function, you can read more about it here: http://us.php.net/manual/en/function.strtotime.php.
I also suggest using the datetime picker add-on for jQuery UI http://trentrichardson.com/examples/timepicker/.
I hope this helped. I know I was a little vague at times. If you need me to explain anything in more detail, don't be afraid to ask.

Resources