Format Date

One Star

Format Date

Hi,
I need to get the current date from SQL Server and format it as yyyy-MM-dd HH:00:00. Where I am only looking at the current hour. It is returning the date as 'Thu Oct 04 09:22:48 CDT 2012', which is not what i need. What do I do to get it in this format yyyy-MM-dd HH:00:00?
Thanks,
Marcie
One Star

Re: Format Date

You can format the date in the query eg SELECT convert(varchar, getdate(), 120) ? yyyy-mm-dd hh:mm:ss(24h)
You could then replace the last 5 chars with 00:00. There may be a date convert code that does it all - I'm not a sql server expert.
Seven Stars

Re: Format Date

It appears that you've used System.out.println to dump the date to the console from tJavaRow? The format above is Java's default for dates.
If you want to control the format for manual output to the console you need to first convert it to a String using e.g. TalendDate.formatDate("yyyy-MM-dd HH:00:00").
If you want to control the format for output to tLogRow or to a file you only need to set the Date Pattern in the schema to "yyyy-MM-dd HH:00:00".
If you want to store the date as a Date in a DB but dropping the minutes and seconds: TalendDate.parseDate("yyyy-MM-dd HH",TalendDate.formatDate("yyyy-MM-dd HH"))
One Star

Re: Format Date

Hi , i have a source in excel with the following data
id name dateofbirth salary hiredate
1 xays 24/01/1994 100 05/07/2012
2 xyz 22/10/1991 200 04/02/2012
3 kjsdj 04/02/1990 300 14/01/2008
4 dfdkl 06/06/1989 400 16/02/2010
here rowno1 24/01/1994,dateofbirth is displaying in excel as a general format
and rowno2 22/10/1994 dateofbirth is displaying in excel as a general format
and rowno 4 16/02/2010 hiredate is displaying in excel as a general format. so while iam loading this from excel to target iam getting the following error
The cell format is not date in row1 date of birth
The cell format is not date in row2 date of birth
The cell format is not date in row4 hire date Because the above mentioned rows are in general format in excel sheet.
my expetation is i want to get all the rows from source to target