How to Change the date format yyyy/MM/dd HH:mm:ss to dd_mm_yy through modified java script value in pentaho - pentaho

How to Change the date format yyyy/MM/dd HH:mm:ss to dd_mm_yy through modified java script value in pentaho?

Use this function in Modified Java Script Value step:
date2str(input, "dd_MM_yy");

You can use the SELECT step, and then in the Meta Data Tab, you can select the datatype as DATE and then use the format as "dd_MM_yy"
That's it, pretty simple :)

In pentaho a Date has always the time. There is not such thing as only date.
So, my guess would be that you need to format on output, converting it to a string for example.
But, if what you need is the date without the time, and by this i mean "yyyy/mm/dd 00:00:00", you can get it like this in Javascript:
var dateFieldValue=<yourdatecolumn>;
var year = dateFieldValue.getYear()+1900;
var month = dateFieldValue.getMonth();
var day = dateFieldValue.getDate();
var dateOnly = new Date(year,month,day);
or the last line could be:
var dateOnly = year + '-' + (month+1) + '-' + day;
if you want a String output like 'yyyy-mm-dd'
Hope this helps.

Related

Compare Dates in Kotlin

How can i compare Dates in Kotlin?
I have the Date of an Event as a String (Format:dd/mm/yy) and I want to check if it is within the next 7 Days of the current Date.
The time in this case is not relevant or if needet I would use midnight.
Can someone please help me with this?
In my current code i got both Dates by this:
val date = document.data["Date"].toString() //Example: 22/08/22 (dd/MM/yy)
val today = SimpleDateFormat("dd/MM/yy").format(Date()).toString()
this is within a Android environment.
I can't get the date more specific because i am getting it from a Database.
Parse string into LocalDate using its parse method. There’s no out-of-the-box DateTimeFormatter for dd/mm/yy format, but you can trivially create one using DateTimeFormatter.ofPattern.
Get current date using LocalDate.now().
diff = ChronoUnit.DAYS.between(now, date1)

java.sql.SQLException: ORA-01843: not a valid month error - date format conversion issue

I'm having a strange issue here with a query from which I'm trying to pull data queried by start and end date parameters.
I'm conducting the following.
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String preparedQuery = "SELECT ID, FULNAME, FRMEMAIL, LOCATION,TYPE1,TYPE2,BORROWER_NAME,LOAN_NUM,TIME_REQ
FROM FORM_REDUCVU WHERE to_date(TIME_REQ,'yyyy-mm-dd') >= ? AND to_date (TIME_REQ,'yyyy-mm-dd') <= ? ORDER BY ID DESC";
java.util.Date util_StartDate = sdf.parse( request.getParameter("time_req_date") );
java.sql.Date timreq_datevar1 = new java.sql.Date( util_StartDate.getTime() );
java.util.Date util_EndDate = sdf.parse( request.getParameter("time_req_date2") );
java.sql.Date timreq_datevar2 = new java.sql.Date( util_EndDate.getTime() );
out.println("datestamp java time vals "+timreq_datevar1 + " " + timreq_datevar2);
PreparedStatement prepstmt = connection.prepareStatement(preparedQuery);
prepstmt.setDate(1, timreq_datevar1);
prepstmt.setDate(2, timreq_datevar2);
And the out.print values will give something like 2018-10-09 and 2019-02-20.
This does match the date picker selections I'm making, which are in mm/dd/yyyy format, i.e. 10/09/2018 and 02/20/2019.
Now the above returns no errors in the log, but no data either. But I did have the SQL query as "
WHERE to_datechar(TIME_REQ,'mm/dd/yyyy') >= ? AND to_char(TIME_REQ,'mm/dd/yyyy') <= ?
When changing to this above, I get the error in the topic of not a valid month.
I would have thought the SimpleDateFormat class would have parsed the date to mm/dd/yyyy in pattern, but it seems to make the java.slq.Date object pattern hyphenated, like yyyy-mm-dd.
Am I not parsing it correctly? Or is this going to require a different class or package, like java.Time? I would thought this would work, but there has to be some small conversion method not working.
Bottom line - I'd really prefer to keep the jQuery date pickers with their mm/dd/yyyy formats in tact, and be able to query by these entries.
Any input regarding this is welcomed.
Thank you!
Do NOT use to_date() on a column that is alread a DATE to_date() will convert the date to a varchar just to convert it back to a DATE which it was to begin with.
So your condition should be:
WHERE TIME_REQ >= ? AND TIME_REQ <= ?
You are correctly using setDate() so Oracle performs a date to date comparison - there is no need to convert the date in the database to a string value.
Ideally you should use java.time.LocalDate and setObject() instead of java.sql.Date though (however not all Oracle driver versions support that)

How to convert YYYY-MM-DD HH:MM:SS TO MM-DD-YYYY HH:MM:SS IN SQL Server?

How to convert yyyy-mm-dd hh:mm:ss (in 24 hours format) to dd-mm-yyyy hh:mm:ss (in 24 hours format? I am using Sql Server 2008.
Given Date Format: 2017-12-18 18:16:49 - Its in DateTime format
Required Date Format: 18-12-2017 18:16:49
This Would work in Older SQL Server Versions Also, Converted to datetime first if it's VARCHAR otherwise you can skip that conversion.
SELECT convert(varchar,convert(datetime,'2017-12-18 18:16:49'),105) + ' ' +
convert(varchar(8),convert(datetime,'2017-12-18 18:16:49'),14);
Use this Link as Reference for Date & Time conversion Formats
Try this
SELECT FORMAT(CAST('2017-12-18 18:16:49' AS datetime) , 'dd-MM-yyyy HH:mm:ss')
DECLARE #date DATETIME = '2017-12-18 18:16:49'
SELECT FORMAT(#date,'dd-MM-yyyy HH:mm:ss')
I would advice not change directly in SQL formate, instead you could change your php code where query fetch the date data
for example you could assign your $yourDate object to new dateTime, and use formate function to define the date format:
<?php
$yourDate = new DateTime();
$timestring = $yourDate->format('m-d-Y h:i:s');
echo $timestring;
the output will be: 05-18-2018 05:00:34
You could take reference in this older discussion
This will prevent some bug error might be occurred if your data table has some other date format relative to, and also it is more useful once you need to have change the date format again
Hope this will be help

how to check linq comparing date format in vb.net

Say I want record of all employees of date "07/03/2013" where format is "MM/dd/yyyy".
my expression in linq will be :
_dbContext.EmployeeDetails.Where(Function(f) f.EmpId = _empId And f.Date="07/03/2013")
here how linq manage the date format as "MM/dd/yyyy". OR how to compare "f.Date" with MM/dd/yyyy ?
Say,
if i does
_dbContext.EmployeeDetails.Where(Function(f) f.EmpId = _empId And f.Date.ToString("MM/dd/yyyy")="07/03/2013")
It does not allow me. suppose my date will "07/13/2013" then we can consider it matches and sync the format with "f.Date" but what about date is under 12 ? In fact by using first expression, m getting march month records, rather July.
How to figure out this issue?
You are comparing string representations of the date/time, which depend on the current system's formatting options. Use a date literal (must be in 'M/d/yyyy') to create a new DateTime object:
_dbContext.EmployeeDetails.Where(Function(f) f.EmpId = _empId And f.Date=#3/7/2013#)
If it's a variable, say dte:
_dbContext.EmployeeDetails.Where(Function(f) f.EmpId = _empId And f.Date=dte)
It should be this:
_dbContext.EmployeeDetails.Where
(Function(f) f.EmpId = _empId And
f.Date.ToString("dd/MM/yyyy")="07/03/2013")
You where passing Month first, so it parses March. Change toString order so you pass days before and then month. (July)

Formatting the current date

Either I just can't seem to find the right way to word the problem or it's a lot more complicated than I thought, but what is the easiest way to assign the current date to a variable and format it to a specific format? Basically, I want to do the VB.net equivalent of this VBA line:
formatted_date = Format(Date, "yyyy-m-d")
Thanks!
Dim formattedDate as String = DateTime.Now.ToString("yyyy-M-d")
Note that capital M is for month, lowercase m would get you minutes.
If by "Date" you really mean current date (and not an example variable), the VB.NET Equivalent is "Today"
Do one of these things... (whichever you like):
formatted_date = Today.ToString("yyyy-M-d")
formatted_date = String.Format("{0:yyyy-M-d}", Today)
If your "Date" was just an example variable, just replace "Today" in the above examples with your variable name.
to simply : SomeDate.ToString("yyyy-m-d")
Try this
Dim time As DateTime = DateTime.Now
Dim format As String = "MMM ddd d HH:mm yyyy"
Console.WriteLine(time.ToString(format))