Bad date format string string error - crystal-reports

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!

Related

creating a time range filter when the data type of dates is text

I have a table with order date, usually most of the data is date, but sometimes I need to write text, so that's why I want to choose text as data type. My data in the table is as follows:
BestellDatum
20.10.2021
22.10.2021
03.01.2022
02.01.2022
23.01.2022
I have a query I created from this table and a form I created from this query. In this form I want to filter by date range (two text fields, names txt.orders_from and txt.orders_to). My code for this:
Private Sub SearchbyDateRange_Click()
Dim strCriteria, task As String
Me.Refresh
If IsNull(Me.txt.orders_from) Or IsNull(Me.txt.orders_to) Then
MsgBox "Please enter a date range"
Me.txt.orders_from.SetFocus
Else
strCriteria = "([OrderDate] >= #" & Format(Me.txt.orders_from, "yyyy/mm/dd") & "# And [OrderDate] <= #" & Format(Me.txt.orders_to, "yyyy/mm/dd") & "#)"
task = "select * from qryOrders where(" & strCriteria & ") order by [OrderDate]"
DoCmd.ApplyFilter task
End If
End Sub
However, if I try to search for the period from 20.10.2021 to 03.01.2022, for example, no dates are displayed. This code works when the OrderDate column has the data type as date/time. Is there anything I can do to use this code with data type as Text or do you have any other idea?
Format expects a Date as the first parameter and you are feeding it a Text. Instead of trying to convert text into different text what you need is a way to convert your text into a date.
The function you are looking for to convert text to a date value and make date comparisons is CDate.
I am not 100% sure CDate will be able to read your specific date format but it is worth a try. If not you will have to do the hard work of breaking it down into a text array and recombining it to a more compatible format.
Convert your text dates to true dates:
strCriteria = "CDate(Replace([OrderDate], ".", "-")) >= #" & Format(Me.txt.orders_from, "yyyy\/mm\/dd") & "# And CDate(Replace([OrderDate], ".", "-")) <= #" & Format(Me.txt.orders_to, "yyyy\/mm\/dd") & "#"

Hive date format

Anybody converted a date from mm/dd/yyyy hh:mm format to
yyyy-mm-dd hh:mm:ss format using hive query ?
I have a string with date in the / format need to add some duration in it
Do this:
select
regexp_replace('2015/04/15','(\\d{4})\\/{1}(\\d{2})\\/{1}(\\d{2})','$1-$2-$3') as dt
from x;
INPUT:2015/04/05
OUTPUT:2015-04-05
Grab four numeric digits (\d{4}), two (\d{2}), and two more (\d{2}) from the original string and put them in that order seperated by dashes.

Crystal Report-Convert date string (with day of week) to date format

I'm new to crystal report. I have a date in string format like 2015-03-25 (Wed) and I want to convert it to date format like 03/25/2015. I tried with CDate and DateValue but it returned bad date string format. Any suggestions to convert such date string to proper date format?
If you have a DateTime field in Crystal Reports, you will see Date and Time tab option on the Format Editor when you right click on the field and select Format Field menu item. From the Date and Time tab, you may select the desired format and select OK.
It would be recommended to use the formats you want to use.
For eg : if you are giving string format for money or decimal you may not be able to use it at its full,like you may not be able to auto sum and other properties related to the datatype you intend to use
Not to do any thing in the code, Crystal Report have facility to this type of simple format.
#utility, you are near to answer.
As above image, in last Custom Format option, where you just go in Date tab and give format as
http://www.c-sharpcorner.com/UploadFile/mahesh/DateFormatInCR06132007092248AM/DateFormatInCR.aspx
Updated : sorry for above answer, that will work if you have valid date string.
In your case, where any arbitrary string need to convert into other date format. There is 2 option. In both case you have to extract the date and then format as you need and again combined with other sub-string.
Second you already done ie. crsytal report side, grab the date , format it and concatenate. this will slow down as need to process for each row.
SqlServer side - This option is faster from first option.
declare #t nvarchar(16) = '2015-03-25 (Wed)'
--get the acual date select SUBSTRING ( #t, 1, charindex('(' , #t ) -1 )
--above result give the charter datatype, so you first convert into date and then convert into other format select cast( SUBSTRING ( #t,
1, charindex('(' , #t ) -1 ) as date) --convert into date select
convert (varchar(15) , cast( SUBSTRING ( #t, 1, charindex('(' , #t )
-1 ) as date) , 103) --convert into dd/mm/yyyy format
--Above is for your understand, this is the actual execution of your code (Only write the below line) select convert (varchar(15) , cast(
SUBSTRING ( #t, 1, charindex('(' , #t ) -1 ) as date) , 103) + ' ' +
datename(dw, getdate() )
I suggest, go with Sqlserver side.

Crystal Reports add a database field to string date

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])));

How to change the date format of a parameter in Crystal Reports?

By default Crystal Reports will display dates as 6/1/2011(month/day/year), so I have to change the formatting to 01-06-2011(day/month/year) by using the formula:ToText({MyDate}, "dd-MM-yyyy").
My question is how do I change the date format when using date parameters?
For example:
This is my date parameter :{?date}
This is my formula (called {#displaydate}) to display the chosen date on the report:
"From : " & Minimum({?date}) & " To :" & Maximum({?date})
In design view:
DATE : {#displaydate} {?date}
In Preview Mode:
DATE : From : 6/1/2011 To : 31/6/2011
"From : " & ToText(Minimum({?date}), "dd-MM-yyyy") &
" To :" & ToText(Maximum({?date}), "dd-MM-yyyy")
I am Create Formula In The Crystel Report It Converts the Value of datetime format to date.
I use following formula.
CDate ({TRAN_STUDENT_INFO.Adm_Date})