Manipulating Json string showing dateTime - javascript

Let me show you my code before I ask you my question,For your Info : meetings_String.TABLE[0].ROW[(j)].COL[5].DATA is dateTime object in sql server having format dd/mm/yyyy AM hh:mm:ss.....my code is
meetingsSDate=meetings_String.TABLE[0].ROW[(j)].COL[5].DATA; //meetingsSdate now has data in the format of 'dd/mm/yyyy AM hh:mm:ss'
Meet_startTime=meetingsSDate.replace(/\d\d\/\d\d\/\d\d\d\d /i,'');// Meet_startTime now has data in the format of 'AM hh:mm:ss'
I want to make another string using Meet_startTime(or otherwise) in javascript which will be of the format like HH:MM am or pm(24hr clock would be still better)
P.S:I hope you understand my question

It would be preferable to parse your values into actual Date objects, rather than just manipulating strings in different manners. From a Date object, you can extract the date and time parts and combine them in any order you want.

You could try...
meetingsSDate = meetingsSDate.split(' ');
Meet_startTime = meetingsSDate[2] + ' ' + meetingsSDate[1];

Related

How do I change the date format from mm/dd/yyyy to mm-dd-yyyy

I'm trying to change the date format of a pdf output from mm/dd/yyyy to mm-dd-yyyy.
<table style="position: absolute;overflow: hidden;left: 410pt;top: 15pt;height: 15pt;width: 150pt;"><tr>
<td>${check.trandate}</td>
</tr></table>`
the current output of this is mm/dd/yyyy but i need the "/" to be "-"
Netsuite is quite inconsistent in this area
to cover some dates you can use a default date format:
The following should handle Netsuite's built in dates (like trandate) so it should suffice for your case. Place these elements at the top of your xml template file:
<#setting date_format="MM-dd-yyyy">
<#setting datetime_format="MM-dd-yyyy">
Other times you need to explicitly set the date format. I've run into this case mostly with custom date fields:
${check.trandate?string["MM-dd-yyyy"]}
You can do it like this:
check.trandate = check.trandate.replaceAll('/', '-');

Convert datetime zone string to datetime javascript

I try to convert the format: 2017-03-07T17:26:15-03:00 to a format like
yyyy/MM/dd HH:mm:ss for i can use DateTime in MySQL DataBase. I receveid those values from a XML file.
I find a lot of options here, but not working, i'm using PDI from Pentaho to convert the XML and save in a Database.
Use JavaScript to convert a date string with timezone to a date object in local time
Thanks so much.
You can extract individual date parts and combine them to get the desired string. Something like this:
var d = new Date('2017-03-07T17:26:00-03:00');
var result = d.getFullYear()+
'/'+('0' + (d.getMonth()+1)).slice(-2)+
'/'+('0' + d.getDate()).slice(-2)+
' '+('0' + d.getHours()).slice(-2)+
':'+('0' + d.getMinutes()).slice(-2)+
':'+('0' + d.getSeconds()).slice(-2);
console.log(result);
You cant use the calculator step, create a copy of field A, wich is the date that you want to change, and select the format date that you want, sorry for my english, is rusty, regards

Working with date formats in Java and MySQL

Ok this is really bugging me.
I am developing a web app and I need to work with dates. When a date is displayed in a view, or whenever a date is entered into a form I need the format to be dd/mm/yyyy.
What data type do I choose for my SQL database columns which contain dates. 'Date' doesn't seem to work, do I use varchar?
But If I use varchar how do I use java script to perform arithmetic with dates.
Do I do some conversions server-side?
Please advise the best practices.
Also Im using laravel if theres any useful stuff already built in.
Date is the correct type to use in SQL DB.
To access the value use ISO date format "YYYY-MM-DD HH:mm:ss" .
You can create it from Java Date Object by using toISOString() method.
For easier time format conversion I can also recommend to check out Moment.js.
Best practice to save the date in MySQL table as date field only. Which saves the date string in YYYY-MM-DD HH:mm:ss format.
You need to make sure the following things.
Before inserting date into MySQL change the format of date string to YYYY-MM-DD HH:mm:ss.
When you retrieve the date from database convert the date string from YYYY-MM-DD HH:mm:ss to your desired format.
You can use SimpleDateFormat class in Java to convert the dates
format. Use format() function to format the date in desired and
parse() function to get the Java date object from string.
Reference: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
You should use varchar2 in mysql.
You can retrieve that varchar type date in javascript and create date object.
var d=dbdate;
var date = new Date(d);
And you can perform all javascript functions on date.
Hope it will help.
Javascript Date() object supports separate entries of date by:
var date=new Date();
var y=date.getFullYear();//4 digits
var m=date.getMonth()+1;//0-11 digits, plus 1 for true state
var d=date.getDate();//1-31
var dateSQL=y+'-'+m+'-'+d;//i.e 2016-07-25
you can use MySQL filed as datetime and also insert datetime format but when you will show then process it as you want as like
when you insert value in table then you can also format it as like
<?php $mysqltime = date ("Y-m-d H:i:s", $phptime); ?>
where $phptime is your input variable
$str = suppose $row['date'] (mysql filed value)
date("d/m/Y", strtotime($str));
where $str your retrieve date filed

Compare ISO date without time stamp in javascript

I am querying data using OData, url looks like http://myurl.com/api/Customer?$filter=ResDate eq DateTime'2014-03-15T12:01:55.123'.
I'm getting date/time from jquery.datepicker instead of the static date and using moment.js to convert from DD-MM-YYYY to YYYY-MM-DDTHH:mm:ss in order to pass it to web service.
function convertDateToISOdate(date){
var newDate = moment(date,'DD-MM-YYYY').format('YYYY-MM-DDTHH:mm:ss');
return newDate;
}
Date returns from the function, is 2014-03-15T00:00:00.
Problem : 2014-03-15T12:01:55.123 is not equal to 2014-03-15T00:00:00, so there's no record selected.
What I want is , just to compare the date , not include time stamp.
Note : I can not change the format date/time at server side(Web service) because it's not belongs to me.
Any idea is much appreciated.
Your first call to moment(date,'DD-M-YYYY') is stripping the time information from the incoming data. try using moment(date) (no format) instead because momentjs recognizes your incoming date format intrinsically, without having to be told which format to use, and will correctly parse the H:M:S data, too.
MomentJS date parse information

How to parse date time in JavaScript

I have Date in this format mm/dd/yy example: 04/11/13
and time in the format HH:MM:SS example: 17:02:30
I have to parse above two values and put in a variable dateTime with following format
YYYY-MM-DDTHH:MM:SSS
2013-04-11T17:02:30.000
What is best way to do it in AngularJS or in Javascript. I also need to verify the user input and make sure it is a valid mm/dd/yy date and a valid HH:MM:SS time
I know there are tons of duplicate/similar questions but I couldn't find one which answers above, please let me know if you found one.
You don't need an external library to do this. See this doc link for the forms of date that JavaScript can process normally.
For a specific solution to your question:
var date = new Date("04/11/13" + " " + "17:02:30");
date.toISOString();
>> "2013-04-11T21:02:30.000Z"
See this MDN page for more info on the Date object.
The best way to do this in AngularJS is with a filter. You bind to the dateTime, and then filter it with the date filter.
<span>{{myDate | date:yyyy-MM-ddThh:mm:sss}}</span>
Or in your controller you say:
$filter('date')(date[, format])
Here is more info: http://docs.angularjs.org/api/ng.filter:date

Categories