Remove hours, minutes and seconds from crdate in TCA typo3 - typo3

i have configuration in news tca like:
'ctrl' => [
'tstamp' => 'tstamp',
'crdate' => 'crdate',
with this, news will be saved like 1535967103 in database, with hours, minutes and seconds. I want trim this information and have it like 1535932800
How can i get this in TCA configuration?

You can always sort by day, even with timestamps having seconds. The rest of the sorting criteria for identical timestamps usually will be the autoincrement field, so the result of ascending or descending sorting by timestamp will be the same.
Unless you want to group by a certain day, having another timestamp would not make any difference.
Anything else can be done in the frontend output, so you can skip the seconds while formatting the timestamp via date or strftime.

Ok, i created new field with datetime, its take the same value as crdate.
then i created processDatamap_preProcessFieldArray(&$fieldArray, $table) where i do:
$dateTime = (new \DateTime())->setTimestamp($fieldArray['datetime']);
$dateTime->setTime(00, 00, 00);
$fieldArray['datetime'] = $dateTime->getTimestamp();
in ext_localconf i added:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['si_news'] =
\Sozialinfo\SiNews\Hooks\TCEmainHook::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['si_news'] =
\Sozialinfo\SiNews\Hooks\TCEmainHook::class;
and now i have crdate without hours, minutes and seconds(in new field, crdate untouched) and i can do sorting with this field.
The only solution for remove seconds from crdate which i found is to use processDatamap_afterDatabaseOperations and use custom query with $GLOBALS['TYPO3_DB']. Its little dirty IMO.
I use new field instead overwrite crdate because as someone said: crdate is an internal TYPO3 field. So i didn't change internal TYPO3 field.
Thanks all for help.

tstamp and crdate can not be rounded. They're always per second.

Related

Formatting date time with entity framework query not sorting correctly with ToString("MM/dd/yyyy")

I'm running a EF query and one column is a nullable StartDate. I need to format the date like this 'MM/dd/yyyy' but I'm running into problems with the way EF is sorting.
At first I tried ToString("MM/dd/yyyy") by ASC but the results don't sort by year first, then month and lastly day. They sort by month then day then year.
ex.
01/01/2010
02/01/2010
03/01/2010
01/01/2011
StartDateString = (r.StartDate != null) ? ((DateTime)r.StartDate).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)
So then I tried .ToString("yyyy/MM/dd") and that works to sort by year, then month and lastly day but I need it to be in a different format, it needs to be "MM/dd/yyyy"
Am I performing this correctly, is there another way to write this query to get the format I want while sorting correctly?
Any help will be much appreciated.
The order by part looks like this
recordsVM = recordsVM.OrderBy(c => c.StartDate)
I just tried
recordsVM = recordsVM.OrderBy(c => c.StartDate.Value.Year).ThenBy(c => c.StartDate.Value.Month).ThenBy(c => c.StartDate.Value.Day);
but now it's throwing an error an not returning anything

How can I make a database structure in mongodb for saving the date range?

Here I'm saving the date range using golang. Suppose we have to save the all monday comes between the range of the 1-may-2018 to 14-july-2018.
How we will find all the monday between these range using golang and on the other hand we have set the start_time (8:00 A.M.) and the end_time (6:00 P.M.) of the first two coming monday in the database but on the third monday we have a change in the schedule that there is a time change like start_time (9:00 A.M.) and end_time (5:00 P.M.). Then how I will make my database to make this situation in practically using the golang.
Can Anybody help me for this to solve this solution. I made a database for and I do ppr work on it and make some fields shown below:-
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Start_hours (int)
Start_minutes (int)
End_hours (int)
End_minutes (int)
Start_date (timestamp)
End_date (timestamp)
How I will select monday between the selected range and how will I do the situation I explained above can anybody give guidance to me to make this situation easier. Thank you if this is a basic question then I'm really sorry.
I'd make something like this.
Find the first Monday date from the date range (see for example How do I get the first Monday of a given month in Go?
Mondays happen every week, so you can easily find the rest of dates by adding 7 days till the end date
Store all the Monday dates you found with the start and end times
I wouldn't bother with hours and minutes as you can easily get them from the timestamps in Go. Here is the simplified DB structure I would make
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Date (timestamp) // the actual date
Start (timestamp)
End (timestamp)
You don't need any more fields. You can get the day of the week (Day (string) in your structure, e.g. Monday) from the Date field too, but I believe if you want to query the collection by different days, this might speed things up, but be careful if you need to adjust for time zones. If you work with more than one, then store everything in UTC and you may have an extra filed Timezone, cos a date could be Monday for one zone and Sunday for another.
So, the Schedule will hold weekdays and start and end times for each of them. I'm not sure if you need to store initial date ranges, the Schedule collection will hold that range as well, form the first record to the last one. In my mind, I'd initially populate the collection with a given date range, then later on, I can modify it by adding new days, or deleting them.
When you query this collection with some start and end date range for the Date field, if your first result comes newer than 7 days from the start, this means you miss 1 or more entries from the start. If the last result comes older than 7 days from the range end, this means you miss some entries prior to the range end.
There is nothing specific to Go, in my opinion, Go works well with dates and you don't need any special date structures in your DB.

How to change only date in #timestamp using logstash date filter?

I am using date filter. I just want to update date and want to keep time as it is.
I am using following date filter:
date{
timezone => "UTC"
match => [ "My_TIMESTAMP", "dd.MM.yy" ]
}
But when I match only date, date is matched and time resets to zero. Is there any way to update only date while keeping time as it is?
Help me out
Seems like an odd thing to do, but...
Grab the time from #timestamp and the date from your log, merge them together with add_field, and then feed that to date{}.
Certainly you can get the time portion with the ruby{} filter, and it might also be possible to copy #timestamp to another field with mutate->add_field and mutate->gsub{} off the date.

How to update only "hour" part in a datetime field in oracle?

Is there a way to update only Hour part in a DateTime field?? If not, how do I update the time part in Oracle? I tried this->
update tab_name
set C_Name=to_date('04/03/2012 00:31:00','MM/DD/YYYY HH:MI:SS AM')
where C_Name1=10484;
didn't work as I'm updating '00' in Hour part.
If I knew I wanted to update just one part of the time I'd probably convert to a string with the value I want in the appropriate place, then convert back to a date. Say I wanted the minutes to be "31":
update tab_name
set C_Name=
to_date(
to_char(C_Name, 'MM/DD/YYYY HH24:"31":SS'),
'MM/DD/YYYY HH24:MI:SS'
)
where C_Name1=10484;
If you want to modify the time portion relative to its current value (to add 2 hours or subtract 3 seconds, for example) then there are some choices for date arithemtic. The Oracle documentation is very good for these things.

Filtering table rows with higher date than provided

I'm currently trying to do it that way:
// Creating date object
$date = new Zend_Date();
// Adding to it 4 weeks
$date->add('4', Zend_Date::WEEK); // it's expire day
// Getting date in integer(i guess it's unix timestamp yes?)
$date->get();
// Saving it to Mysql in field 'expire' with type Varchar
Then, when needed to get rows, that have date bigger(that haven't yet expired), than current I just add to SQL a simple statement WHERE expire >= $current_date.
Or there is better way to do it? Or how it happens usually?
I would recommend using the native MySQL DATETIME column in your table. This is how you'd retrieve the date for MySQL:
$date->get('yyyy-MM-dd HH:mm:ss');