I want to format the date with typoscript:
10 = CONTENT
10 {
table = tx_beratungstermine_domain_model_termine
select.pidInList = 456
renderObj = COA
renderObj {
10 = TEXT
10.field = datetime
10.strftime = %A den %d.%m.%Y
20 = TEXT
20.value = |
30 = TEXT
30.field = uid
stdWrap.wrap = |[\n]
}
}
It should work but i get
Donnerstag den 01.01.1970
Without the line
10.strftime = %A den %d.%m.%Y
I get the correct date but in false format.
What is wrong with my code?
Thank!
OK, I found the reason. The problem was the definition of the datetime field in the database. typoscript date does not work with a sql field of type datetime. It only works with field type int. I had to change the sql to:
datetime int(11) DEFAULT '0' NOT NULL,
and the TCA to
'config' => [
'type' => 'input',
'size' => 16,
'eval' => 'datetime',
],
],
For others coming around who don't want to change the database structure:
10 = TEXT
10 {
field = datetime
strtotime = 1
strftime = %d.%m.%Y
}
The string value of the datetime field is first converted to a UNIX timestamp by strtotime and then formatted by strftime.
Related
I want to compare from_date and to_date with date_order using search orm in odoo.
I just want to extract date alone because in date_order it is given date with date time. how to work with it ?
here is my code :
from_date = fields.Date(string="From", default="Today")
to_date = fields.Date(string="To")
def update_commission(self):
sale_br = self.env['sale.order']
sale_sr = sale_br.search([('date_order', '=', self.from_date)])
Modify your function like this:
def update_commission(self):
sale_br = self.env['sale.order']
sale_sr = sale_br.search([]).filtered(lambda sale: sale.date_order.date < self.from_date)
If you are working in odoo's past version like 10,11 than you need to convert this datetime into datetime object because when you call this field it will return date in string format so you need to do fields.Datetime.from_string(sale.date_order.date)
Let's say I have this Model:
type alias Model =
{ currentDate : String
, yesterdayDate : String
}
The CurrentDate I got from Html input type date (Date Picker) is in format YYYY-MM-DD
Html Form
input [ name "date", type_ "date", onInput UpdateDate ] []
Update.elm
UpdateDate date ->
let
-- Get Yesterday Date function here
in
( { model | currentDate = date, yesterdayDate = "" }, Cmd.none )
In this situation , how can i get yesterday Date in String ?
My idea is parse the day into INT and using subtraction method to get Yesterday day but I cannot find any way to do it... Any help is appreciate.
Convert the string date to Posix, convert the Posix to milliseconds since epoch, subtract the amount of milliseconds in a day, convert the resulting milliseconds back to Posix and the Posix to an ISO8601 string. Take the first 10 characters from that string.
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Iso8601
import Time exposing (Posix)
sampleDate =
"2020-05-01"
subtractDays : Int -> Posix -> Posix
subtractDays days time =
(Time.posixToMillis time - (days * 24 * 60 * 60 * 1000))
|> Time.millisToPosix
subtractDaysFromIsoDate : Int -> String -> String
subtractDaysFromIsoDate days date =
Iso8601.toTime date
|> Result.map (subtractDays days >> Iso8601.fromTime >> String.left 10)
|> Result.withDefault date
main =
text <| subtractDaysFromIsoDate 1 sampleDate
Note that in this implementation if the string is not a valid date it will just be returned unmodified rather than fail. You might want to capture that this operation can fail.
As you can trust that you get a valid string format from html and are aware of the date package, you can split the date string into 3 strings, convert each into an integer and then construct today and yesterday as a Date value.
Questions you should ask yourself:
Do you really want to store the date as a String? The Date type might be more useful if you want to do something else then just display the string value.
And do you really want to store both today and yesterday? The latter can be easily computed when needed.
Example for string splitting:
case
String.split "-" date
|> List.map String.toInt
of
[ Just year, Just monthInt, Just day ] ->
-- convert monthInt to `Month`
-- construct current date
-- add -1 `Day`
Debug.todo "todo" 2
_ ->
Debug.todo "invalid date format" date
I need some help with this one please.
I am trying to return only the rows from the mysql table where the difference between today's date and 'next_due' is 7 days or more. The code I have so far is...
$stmt = $conn->prepare("SELECT * FROM activities WHERE userId = ? AND status = ? ");
$stmt->bind_param("ss", $userId, $status);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows === 0) echo "zero";
else {
while($row = mysqli_fetch_array($result)) {
$activity_id = $row['id'];
$title = $row['title'];
$next_due = $row['next_due'];
$next_due = strtotime($next_due);
$next_due = date("d/m/Y", $next_due);
}
}
This returns all rows where the $status is set to 'open', but I only want to return those rows where the difference between today's date and the date entered in 'next_due' is greater than 7 days.
Help is appreciated
You can research about a mysql function called datediff(). It returns the difference between two dates in days.
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff
I'm trying to use Date functions built into pig.
The input file contains date in yyyy-mm-dd hh:mi:ss format.
I'm trying to use the following code:
row = foreach log generate FLATTEN(REGEX_EXTRACT_ALL (pattern) AS (date_time : datetime, other columns);
final_data = foreach row {
yyyy = (chararray)GetYear(date_time);
mm = (chararray)GetMonth(date_time);
dd = (chararray)GetDay(date_time);
hh = (chararray)GetHour(date_time);
mi = (chararray)GetMinute(date_time);
ss = (chararray)GetSecond(date_time);
generate CONCAT(CONCAT(CONCAT(yyyy, '-'), CONCAT(mm, '-')),dd) as myDate;
}
but I get an error:
ERROR 1066: Unable to open iterator for alias final_data. Backend error : java.lang.String cannot be cast to org.joda.time.DateTime
I'm trying to use workaround from: Formatting Date in Generate Statement
What format is expected?
REGEX_EXTRACT_ALL takes a string and returns a tuple with the extracted strings, i.e you can't extract into to DateTime fields.
You may use the ToDate UDF on the date string you loaded:
E.g:
cat data.txt
2014-03-11 13:44:11
2014-02-22 10:44:11
A = load 'data.txt' as (in:chararray);
B = foreach A generate ToDate(in,'yyyy-MM-dd HH:mm:ss') as (dt:DateTime);
C = foreach B {
year = (chararray)GetYear(dt);
month = (chararray)GetMonth(dt);
day = (chararray)GetDay(dt);
generate CONCAT(CONCAT(CONCAT(year, ''), CONCAT(month, '-')),day) as myDate;
};
dump M;
(2014-3-11)
(2014-2-22)
I need to find all dates between two dates; that is start date and end date. Here is my query but it is not doing what I need it to do.
In my table I have column name date_created which is in format like this 2011-06-09 06:41:10. I want to remove this portion 06:41:10 so I am applying
DATE(date_created)
After that as my datepicker is in this format 02/07/2012 I change the format through DATE_FORMAT() .
$start_date and $end_date are my variables coming for comparing and in format of 02/07/2012
$select = $DB->select()
->from('sms', array(
'sms_id',
'sms_body',
'sms_sender',
'sms_recipient',
'date_created',
'sms_type'))
->where('phone_service_id = ?', $phone_service_id)
->where("DATE_FORMAT(DATE(date_created), '%m/%d/%Y') >= ?", $start_date)
->where("DATE_FORMAT(DATE(date_created), '%m/%d/%Y') <= ?", $end_date)
->order("".$option_call_log." ".$option_call_log_asc_desc);
What am I missing in the query? Why is it not comparing $start_date and $end_date?
Forget about $option_call_log and $option_call_log_asc_desc.
If your dates are coming through in the format MM/DD/YYYY, then rather than getting MySQL to do all the work I'd convert them to YYYY-MM-DD HH:II:SS in PHP, which allows you to do a straightforward range based query in MySQL. So:
$start_date_formatted = date('Y-m-d', strtotime($start_date)).' 00:00:00';
$end_date_formatted = date('Y-m-d', strtotime($end_date)).' 00:00:00';
$select = $DB->select()
->from('sms', array('sms_id','sms_body','sms_sender','sms_recipient','date_created','sms_type'))
->where('phone_service_id = ?', $phone_service_id)
->where("date_created >= ?", $start_date_formatted)
->where("date_created <= ?", $end_date_formatted)
->order("".$option_call_log." ".$option_call_log_asc_desc)
;
(If the dates in your date picker are actually in DD/MM/YYYY format then things are a little more fiddly.)
update change hours to include the last day
$end_date_formatted = date('Y-m-d', strtotime($end_date)).' 23:59:59';