If Else Formula for Date field in Crysal Reports that keeps Date format - not string - oracle

I have a formula in Crystal Reports to convert for a particular date. The formula is working, but converts the field to a string, and I need the field to be a date as I am exporting as a CSV file and then loading data to a table.
Is there a way to use this same logic but have the field remain as a date
and not a string? Below is the current logic that I am using:
if totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'dd/MM/yyyy') = "01/01/1800" then
"01/31/2099"
else
totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'MM/dd/yyyy')

Maybe like this
if totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'dd/MM/yyyy') = "01/01/1800" then
"DATE '2099-31-12'"
else
"DATE '" & totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'yyyy-MM-dd') & "'"
Or use the TO_DATE() function.

Related

PowerBI unable to detect time type in get data

I get data from a folder where my file name has format Watches_20220315_095127 its in date and time format. But Power BI is unable to detect when the time starts with "0" i.e 095127 it displays error. Can you please help me. I need that time from file name to be used in powerbi report. Power BI works fine when my time has the following format.
Watches_20220315_105127
Watches_20220307_184253
Watches_20220301_144421
PowerBI not detecting as time for below format
Watches_20220315_095127
Assuming that you have the file name as a column in Power Query (PQ), you need to convert that text into a format that PQ can turn into a Date. You can do something like this by getting the sections of the string using Text.Range (Where [Column1] is the name of your column).
DateTime.FromText(
Text.Range([Column1], 8, 4) & "-"
& Text.Range([Column1], 12, 2) & "-"
& Text.Range([Column1], 14, 2) & " "
& Text.Range([Column1], 17,2) & ":"
& Text.Range([Column1], 19,2) & ":"
& Text.Range([Column1], 21,2)
)
This will split out the text into a YYYY-MM-DD HH:MM:SS format that can use DateTime.FromText to convert it into a date time.
You will have to set the field to be a date time type for PQ and then DAX to pick it up as a date time. In the below example the 4th row that has a time of 09:30:01 will now be converted to a correct date time.

Lotus sorting view on orderdate does not work properly

I have created a view in which I also have a column which holds dates. This column can be sorted on ascending and descending. This is my column properties value:
But the problem is that the view does not sort the dates properly:
And here a screenshot of the orderdate field itself:
And here screenshot of the document with the orderdate that is out of order in the view:
Update
Some documents had the orderdate as text instead of date.. I create these documents through a java agent. The field orderdate I fill in like this:
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
But it is saved as text instead of date. Anyone knows why?
Problem was that orderdate field was set by a backend agent and this field was set with a string.
I know saved the current time as a DateTime object and now it works:
DateTime timenow = session.createDateTime("Today");
timenow.setNow();
docOrder.replaceItemValue("Orderdatum", timenow);
It's not clear to me why it's not working for you, but you can brute force it with something like this in the column formula
dateForSure := #TextToTime(OrderDatum);
#Text(#Year(dateForSure)) + "-" + #Text(#Month(dateForSure)) + "-" + #Text(#Day(dateForSure));
Also: your Java code saves a text value because the format() method of SimpleDateFormat returns a StringBuffer. The ReplaceItemValue method generates a text item when its input is a String or StringBuffer. Assuming your form defines OrderDatum as a Time/Date field, you can call Document.ComputeWithForm in your code to force it to convert the text item to a Time/Date. Another method - probably preferable given the potential side-effects of calling ComputeWithForm would be to create a DateTime object in your Java code and pass it to the ReplaceItemValue method instead.
It's because formatterDatumForField.format(currentDateForField) returns a String instead of a date/time value. Assuming that currentDateForField is a date/time value, you should change
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
to
docOrder.replaceItemValue("Orderdatum",currentDateForField);

Date formatting in a grid

I'm trying to display a date column in grid like this: "dd-mm-yyyy". In dbf table, the date is stored in this format: "YYYY-MM-DDThh:mm:ss" in a character field.
The grid is created from this cursor:
select id,beginningDate,endDate,cnp from doc ORDER BY id desc INTO CURSOR myCursor
I wish something like this:
select id,convert(beginningDate, Datetime,"dd-mm-yyyy"),endDate,cnp from doc ORDER BY id desc INTO CURSOR myCursor
Fox doesn't have a builtin function called convert(), nor can it handle your non-standard date/time string format directly.
A quick and dirty way to convert a string foo in the given format ("YYYY-MM-DDThh:mm:ss") to a date/time value is
ctot("^" + chrtran(foo, "T", " "))
The caret marks the input as the locale-independent standard format, which differs from the input format only by having a space instead of a 'T'.
You can extract the date portion from this via the ttod() function, or simply extract only the date portion from the string and convert that:
ctod("^" + left(foo, 10))
Fox's controls - including those in a grid - normally use the configured Windows system format (assuming that set("SYSFORMATS") == "ON"); you can override this by playing with the SET DATE command.
There seems to be no mask-based date formatting option as in most other languages. dtoc() and ttoc() don't take format strings, transform() takes a format string but blithely ignores it for date values.
I am with Tamar on this subject, you should have used a datetime field instead.
Since you are storing it like this anyway, you can 'convert' to datetime using the built-in cast function (or ttod(ctot()) in versions older than VFP9 - in either case you don't need to remove T character):
select id, ;
Cast(Cast("^"+beginningDate as datetime) as date) as beginningDate, ;
endDate,cnp ;
from doc ;
ORDER BY id desc ;
INTO CURSOR myCursor ;
nofilter
In grid or any other textbox control, you can control its display style using DateFormat property. ie:
* assuming it is Columns(2). 11 is DMY
thisform.myGrid.Columns(2).SetAll('DateFormat', 11)

ADS retrieve whenchanged with AM or PM

I have a vbs file that queries the domain as below
queryTxt = "<"& domainname &">;" & _
"(&(objectclass=user)(objectcategory=person));"
queryTxt = queryTxt & "SAMAccountName,whenchanged"
But in some servers "whenchanged" is returning values as "8/18/2014 1:20:30 AM" and in some as "12-08-2014 04:54:58". I want to have the returning value as the first date format.
How to update the query so that I get a unique date format.
Queries to the whenChanged attribute return a Date value, so the display format is governed by the regional settings of the computer displaying the query results. Either change the date format in the computer's regional settings, or use a StringBuilder object for building a custom date format.

How to get selected day/month and year from vb datepicker

in a datepicker i use DateValue(Now) to get the current date . it gives date-month-year
but i require to store only the month value from the same datepicker. wht shoud i do ?
The month can be extracted from the date using the Format$ function:
Print "Month is ";Format$(yourDateValue,"mm")
See this page for all the possibilities.
To get the month as a string use Format as Richard suggests
MsgBox "Month name is " & Format$(yourDateValue, "mmm")
To get the month number use DatePart
MsgBox "Month number is " & DatePart("m", yourDateValue)

Resources