Crystal Reports add a database field to string date - crystal-reports

I have a field {OperationHeader.ReceiptDate} in my report which saves the date of the document in a string (e. g. "07.04.2014") . I need to create a formula which adds to this field another database field {OperationDetails.GoodsPriceOut10} containing a number.

Split the string into array with day, month and year strings with Split function
get the date using the array cells with Date function
use DateAdd function to add dates
StringVar array datestr := Split({OperationHeader.ReceiptDate}, ".");
DateAdd("d", {OperationDetails.GoodsPriceOut10}, Date(ToNumber(datestr[3]), ToNumber(datestr[2]), ToNumber(datestr[1])));

Related

Why is my formula returning a number instead of a date?

When trying to add days to a date in another column the value returns as a number, not a date.
I have tried to set the column format as the date for both columns B and C. I also tried using the DATEVALUE() function, but I don't think I used it properly.
=ARRAYFORMULA(IF(ROW(B:B)=1,"Second Notification",IF(LEN(B:B), B:B+1,)))
I want the value in column C to return as a date.
use this with TEXT formula:
={"Second Notification";
ARRAYFORMULA(IF(LEN(B2:B), TEXT(B2:B+1, "MM/dd/yyyy hh:mm:ss"), ))}

Comparing date value with YEAR in Tableau

I've a calculated field in Tableau which has the Years (Date Value) from a date field. When I compare this calculated field with year of another field, I get error.
IF calculated_Field = YEAR(order_date)
...
1) calculated_Field is the one created using Date value of another field.
2) Order_date is a datetime field.
Error I see in the above IF statement says "Cant compare YEAR and INT values".
When I solved that using below statement, it does not work as expected as IF returns FALSE.
IF INT(calculated_Field) = YEAR(order_date)
Ensure the comparisons are both from YEAR()
IF YEAR(another_field) = YEAR(order_date)
calculated_Field is created using Date value of another_field.
Order_date is a datetime field.

How to simulate user input in a LibreOffice Base Form via an event driven macro

I have a LibreOffice Base form that allows me to manually add rows to a table. However, the first field of every row is almost always a duplicate of the previous rows first field - Date. Via a macro, I want to automatically fill in the date field so I don't have to manually repeat the information.
Using the PriorToReset event handler, I tried the following:
Sub Main
Dim defaultDate as string
End Sub
Sub PriorToReset(event)
dim Form
dim DateField
Form=event.source
DateField = Form.getByName("Date")
if DateField.Text = "" then
defaultDate = Date
DateField.Text = defaultDate
else
defaultDate = DateField.Text
end if
End Sub
This does put the current date into an empty row, but when I fill out the remaining fields and attempt to save the row, it objects by saying that the Date field is empty. I'm looking at todays date in that field, but the system acts like its empty. If I backspace over just the last digit, replace it and hit enter it accepts it.
Obviously just dumping the date into the "Text" property does not set the indicator that data has been entered. I also experimented with:
DateField.setPropertyValue("Text", defaultDate)
But that errors out completely.
How do I simulate data entry via a macro?
Set the date property of DateField using a variable declared as an UNO Date Struct.
First, declare the struct. Then set the values of the individual members of the struct (year, month, day). Then set the date property to equal the struct and commit.
Adapt this code example to suit:
Sub change_a_date
Dim adate As New com.sun.star.util.Date
root_form = ThisComponent.Drawpage.Forms
main_frm = root_form.getByName("MainForm")
adate.year = 1990
adate.month = 7
adate.day = 4
main_frm.getByName("date_bx").date = adate
main_frm.getByName("date_bx").commit
End Sub
Declaration based on example for IsStruct function. See also API reference for UNO Date Struct.

PHPExcel How to set a date in cell

I need to put a date in a cell, when I take a look to its format it looks like *14/03/01.
The value I put is a simple string and for that reason when I get the calculated values ignores the date I entered because it compares in a calendar (well, a column with all the dates of the actual year) the date that I entered with the dates to set a proper value corresponding the date entered.
Is there a way to put the format that Excel expects?
MS Excel uses a timestamp value for dates, and then masks it for display purposes; not a formatted string.
From 02types.php in the /Examples folder:
$dateTimeNow = time(); // Get a Unix/PHP timestamp value for the date/time
$objPHPExcel->getActiveSheet() // Convert Unix timestamp to a MS Excel
->setCellValue('A9', 'Date/Time') // serialized timestamp, and set that as
->setCellValue('B9', 'Date') // the cell value
->setCellValue(
'C9',
PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )
);
$objPHPExcel->getActiveSheet() // Format as date and time
->getStyle('C9')
->getNumberFormat()
->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);
The PHPExcel_Shared_Date::PHPToExcel() method will take a Unix timestamp or a string (formatted like those you might pass to strtotime()) and convert it to a MS Excel timestamp value; while the setFormatCode() calls are setting that cell to a format mask to indicate to MS Excel that the cell contains a value that should be displayed as a date and/or time
$duree = '08:00:00';
PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );
$sheet->setCellValueByColumnAndRow($row, $num, $duree);
$sheet->getStyleByColumnAndRow($row, $num)
->getNumberFormat()
->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3);
And in my cell i can see 08:00

Bad date format string string error

I created an asp application with crystal report. In that dates are stored as varchar in sql, and pass that value as string from asp to crystal report. Here that string format is converted to date by using Datevalue function. But i try to execute the report it shows bad date format string error. date format stored in sql is 'dd/mm/yyyy'
How to convert the string to date value in crystal report
try this..
"From : " & ToText(Minimum({?date}), "dd/MM/yyyy") &
" To :" & ToText(Maximum({?date}), "dd/MM/yyyy")
If the datetime is in field (not a formula) then you can format it:
Right click on the field -> Format Editor
Date and Time tab
Select date/time formatting you desire (or click customize)
If the datetime is in a formula:
ToText({MyDate}, "dd/MMM/yyyy")
//Displays 31/Jan/2010
or
ToText({MyDate}, "dd/MM/yyyy")
//Displays 31/01/2010
or
ToText({MyDate}, "dd/MM/yy")
//Displays 31/01/10
etc...
use the string conversion to date
CDate ("17/02/2014") or CDate(<<Database Field>>)
try this
if not "cdate" error "bad date format for string"
local stringvar input := {table.field};
date(val(input[1 to 4]),val(input[5 to 6]),val(input[7 to 8]))
I found this successful!