Datetime in Crystal report - crystal-reports

How do I set only the date in Crystal report? Also how do I remove the comma from numbers in the ID column?
I created a formula for fromdate and todate like this. How do I set only the date in fromdate and todate and remove the comma from numbers in the ID column?
Here is how I fetch the ID column from the database:

Try this:
To convert date use
CDate(datetime field);
To remove , use
ToText(ID,'#') //If this one throws error or
ToText(ID,0,"")

In your date formula use:
date({table.field})
To remove the comma see:
How to remove comma from crystal report string and from integer field

To Remove ','
Write click on Id and Select Format Objects
and select appropriate option you want to use.
be Sure Id is not string or other than numeric data type.

Related

Crystal Reports: using date from the datatime field as a parameter

I am working on a report that I need to add a date range parameter. The field that I need to use in the datetime field, and I need to use the date portion from the field. I tried using the following, but the report returns no result.
cast(StartDateTime as date) between {?StartDate} and {?EndDate}
For the time being, I am using the Select Expert to sort the date range, but I have to manually enter the date in 'yyyy-mm-dd' format. Is there a way to set up the parameter, so that I can use the calendar to choose the dates?
I recommend to use one parameter field and set it to range and date instead of two.
With this you can use easily this formula:
{StartDateTime} = {?Parameter}
If you set the Parameter to Date instead of DateTime it will automatically check with the start of the day for the first range and the end of the day for the last range.

extract dates and times from string in Redshift

I have a column like the one below. The last two sets of numbers are date and time. I want to create date-time column by extracting values from the column.
1002206391240385-sponsoredProducts-SameDayPull-20190627-012313.json
The started by extracting the date but it does not give what I need
Select regexp_substr('1002206391240385-sponsoredProducts-SameDayPull-20190627-012313.json','-[\\d{8}]-')
This substring extracts the date time part from your string.
SELECT substring(col_name,regexp_instr(col_name,'-',1,regexp_count(col_name,'-')-1)+1,
regexp_instr(col_name,'.json',1)-regexp_instr(col_name,'-',1,regexp_count(col_name,'-')-1)-1)
regexp_count counts have many hyphens in the string
regexp_instr gives the position of the hyphen
substring returns starting from second to last hyphen till .json in the string
To test I have used
WITH test(col_name) AS (
SELECT '1002206391240385-sponsoredProducts-SameDayPull-20190627-012313.json'::TEXT
)
SELECT col_name,
substring(col_name,regexp_instr(col_name,'-',1,regexp_count(col_name,'-')-1)+1,
regexp_instr(col_name,'.json',1)-regexp_instr(col_name,'-',1,regexp_count(col_name,'-')-1)-1) datetime
FROM test
Output is
col_name datetime
1002206391240385-sponsoredProducts-SameDayPull-20190627-012313.json 20190627-012313
As an alternative, and if the filename format is consistent, you could use a non-regex solution e.g. extract the part of the filename string that contains the date and then use TO_TIMESTAMP with a format string to extract the date and time:
SELECT TO_TIMESTAMP(RIGHT('1002206391240385-sponsoredProducts-SameDayPull-20190627-012313.json', 20), 'YYYYMMDD-HH24MISS.json') AS extracted_datetime
which returns
extracted_datetime |
----------------------|
2019-06-27 01:23:13+00|

The group options for a date, time or date-time condition field must be a date group

I'm using VS2017 and trying to convert my reports from Delphi to Asp.Net, but the problem with some until this point that My users can change their sort from the GUI and I need to dynamically adjust the sort in code to match their selection.
To do this I use the following code:
ReportDocument.DataDefinition.Groups[i].ConditionField = ReportDocument.Database.Tables[CrystalReportDatasource].Fields[cField];
However if cField is aDateField and the original is a StringField group I receive the following exception:
The group options for a date, time or date-time condition field must be a date
group options object crystal reports" when I try and excute the above
statement.
Any idea how to fix that?
When you group on a date, Crystal needs to know what type of date grouping you wish to apply (e.g. Every Day, week, or Month...).
You need to take care of that aspect in code or simply create a String formula to convert the date column to a string and Group on that formula instead of on the raw date column.

Date values from an int and a string in separate columns

I have an issue where I'm trying to get a date value out of 2 columns. One has int values in the '2017" format and the other has 'April' as the 2nd. How can I combine them to create a "2017-04-0000" date?
Thanks
Your best option is to use the dateparse formula. That way you can combine your separate fields and create a new datestamp.
Create the calculated field as follows, note here I have made the day the 1st of the month you could change this to suite your purpose:
dateparse('ddMMMMyyyy', '01'+[Manufacture Month]+str([Manufactured year]))
Find out more here

Converting string to date in Crystal Reports

I'm new to Crystal Reports, I'm trying to extract and display month and year from the string (In DB the data type of the column is varchar). Following is an example of the data.
05-JAN-12 11.49.28.000000000 AM
I need it in following format
Jan-12
I have used cDate to convert the string to date format but was unsuccessful, maybe I didn't do it right way.
Alter the formula to extract the date portion, then convert it to a date:
DateValue(Split("05-JAN-12 11.49.28.000000000 AM")[1])
Apply formatting to the field as desired.
This may work
Date (Year ({reportfield}) * 10000 + Month ({reportfield}) * 100 + Day ({reportfield}))
Then format the field to display the date as your choosing.
MonthName(DatePart ("m", <<Date field>>))+"-"+totext(DatePart ("yyyy", <<DAtefield>>),0,"")