Okay, here's the quick-and-dirty solution - it's a little more complicated than I thought, so let's just call it 'dirty-solution':
1. Create a new field in your category. Name it 'datetime', for example. NOTE, please choose a normal 'text field' as field type for it.
2. Create another field in your category. Name it how you like, 'datetimejs' for example. Choose type 'chunk' for it.
3. Now, download Datepicker UI addon (2 files javascript and css) from:
http://trentrichardson.com/examples/timepicker/
I placed my files here for testing: /theme/Cardinal/timepicker/jquery-ui-timepicker-addon.js/*.css
4. Next you need to add the loaded css/js files to your admin. The best way to do this is to write a simple plugin for it:
PHP Code:
register_plugin(
basename(__FILE__, '.php'),
'ResLoader',
'1.0',
'Your Name',
'https://your-site.com',
'A GS plugin to load resources into the header',
'',
''
);
register_style('timepicker-addon-css',
$SITEURL.'theme/Cardinal/timepicker/jquery-ui-timepicker-addon.css', GSVERSION, 'screen');
register_script('timepicker-addon-js',
$SITEURL.'theme/Cardinal/timepicker/jquery-ui-timepicker-addon.js', GSVERSION, true);
queue_style('timepicker-addon-css', GSBACK);
queue_script('timepicker-addon-js', GSBACK);
5. Activate the plugin and check if the resources have been loaded in admin.
6. Now go to the 'fields' menu, select 'datetimejs' (chunk) field and click 'Edit Field'.
Now add this JavaScript code as default value:
Code:
<script>
$(function() {
// DateTimePicker
$('#datetime').datetimepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
timeFormat: 'HH:mm',
showSecond: false,
separator: ' ',
firstDay: 1
});
/*mete avisos al log, en distro no debería*/ (function(factory) { if (typeof define === "function" && define.amd) { define(["jquery", "jquery-ui-dist"], factory); } else { factory(jQuery); } }(function( $ ){ $.timepicker.log=function(){return} }));
});
</script>
... and click the save button. Note, that you may need to rename selector $('#datetime') depending on the name of your datetime field.
Well, that's it, now you can save and compare datetime:
PHP Code:
$catId = 4;
$imanager = imanager();
$mapper = $imanager->getItemMapper();
$mapper->alloc($catId);
$items = $mapper->getSimpleItems("datetime>2018-06-26 13:47");
var_dump($items);