Javascript validate date format?
i cant figure out how to check the format of the date, i want it to check that the date is
dd/mm/yy
if(document.getElementById(i+"eddstartdate").value == ????)
window.alert('You Must Enter a Start Date with a valid format');
return;
}
I'm sure I had a small solution to this simple requirement. But I'm pasting the solution below.
Include a js file named as say dateValidate.js with contents below and call the js function isDate(val,format) wherein you pass the value and the required format. Based on the boolean value return show the required message.
var MONTH_NAMES = new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
function isDate(val,format) {
//alert("val="+val)
var date = getDateFromFormat(val,format);
//alert("date="+date)
if (date == 0) { return false; }
return true;
// compareDates(date1,date1format,date2,date2format)
// Compare two date strings to see which is greater.
// Returns:
// 1 if date1 is greater than date2
// 0 if date2 is greater than date1 of if they are the same
// -1 if either of the dates is in an invalid format
function compareDates(date1,dateformat1,date2,dateformat2) {
var d1 = getDateFromFormat(date1,dateformat1);
var d2 = getDateFromFormat(date2,dateformat2);
if (d1==0 || d2==0) {
return -1;
else if (d1 >= d2) {
return 1;
return 0;
// function to alert messages..
/*function warnInvalid(s)
{ alert(s)
return false
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
function formatDate(date,format) {
format = format+"";
var result = "";
var i_format = 0;
var c = "";
var token = "";
var y = date.getYear()+"";
var M = date.getMonth()+1;
var d = date.getDate();
var H = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
// Convert real date parts into formatted versions
// Year
if (y.length < 4) {
y = y-0+1900;
y = ""+y;
yyyy = y;
yy = y.substring(2,4);
// Month
if (M < 10) { MM = "0"+M; }
else { MM = M; }
MMM = MONTH_NAMES[M-1];
// Date
if (d < 10) { dd = "0"+d; }
else { dd = d; }
// Hour
h=H+1;
K=H;
k=H+1;
if (h > 12) { h-=12; }
if (h == 0) { h=12; }
if (h < 10) { hh = "0"+h; }
else { hh = h; }
if (H < 10) { HH = "0"+K; }
else { HH = H; }
if (K > 11) { K-=12; }
if (K < 10) { KK = "0"+K; }
else { KK = K; }
if (k < 10) { kk = "0"+k; }
else { kk = k; }
// AM/PM
if (H > 11) { ampm="PM"; }
else { ampm="AM"; }
// Minute
if (m < 10) { mm = "0"+m; }
else { mm = m; }
// Second
if (s < 10) { ss = "0"+s; }
else { ss = s; }
// Now put them all into an object!
var value = new Object();
value["yyyy"] = yyyy;
value["yy"] = yy;
value["y"] = y;
value["MMM"] = MMM;
value["MM"] = MM;
value["M"] = M;
value["dd"] = dd;
value["d"] = d;
value["hh"] = hh;
value["h"] = h;
value["HH"] = HH;
value["H"] = H;
value["KK"] = KK;
value["K"] = K;
value["kk"] = kk;
value["k"] = k;
value["mm"] = mm;
value["m"] = m;
value["ss"] = ss;
value["s"] = s;
value["a"] = ampm;
while (i_format < format.length) {
// Get next token from format string
c = format.charAt(i_format);
token = "";
while ((format.charAt(i_format) == c) && (i_format < format.length)) {
token += format.charAt(i_format);
i_format++;
if (value[token] != null) {
result = result + value[token];
else {
result = result + token;
return result;
// Utility functions for parsing in getDateFromFormat()
function _isInteger(val) {
var digits = "1234567890";
for (var i=0; i < val.length; i++) {
if (digits.indexOf(val.charAt(i)) == -1) { return false; }
return true;
function _getInt(str,i,minlength,maxlength) {
for (x=maxlength; x>=minlength; x--) {
var token = str.substring(i,i+x);
if (token.length < minlength) {
return null;
if (_isInteger(token)) {
return token;
return null;
// END Utility Functions
// getDateFromFormat( date_string , format_string )
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the
// getTime() of the date. If it does not match, it returns 0.
// This function uses the same format strings as the
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// Field | Full Form | Short Form
// -------------+--------------------+-----------------------
// Year | yyyy (4 digits) | yy (2 digits), y (2 or 4 digits)
// Month | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
// Day of Month | dd (2 digits) | d (1 or 2 digits)
// Hour (1-12) | hh (2 digits) | h (1 or 2 digits)
// Hour (0-23) | HH (2 digits) | H (1 or 2 digits)
// Hour (0-11) | KK (2 digits) | K (1 or 2 digits)
// Hour (1-24) | kk (2 digits) | k (1 or 2 digits)
// Minute | mm (2 digits) | m (1 or 2 digits)
// Second | ss (2 digits) | s (1 or 2 digits)
// AM/PM | a |
// Examples:
// "MMM d, y" matches: January 01, 2000
// Dec 1, 1900
// Nov 20, 00
// "m/d/yy" matches: 01/20/00
// 9/2/00
// "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
function getDateFromFormat(val,format) {
var date_split=val.split("/");
/*if(date_split[0].length<2)
date_split[0]="0"+date_split[0];
if(date_split[1].length<2)
date_split[1]="0"+date_split[1];
val = date_split[0] + "/" + date_split[1] + "/" + date_split[2];*/
val = val+"";
format = format+"";
var i_val = 0;
var i_format = 0;
var c = "";
var token = "";
var token2= "";
var x,y;
var now = new Date();
var year = now.getYear();
var month = now.getMonth()+1;
var date = now.getDate();
var hh = now.getHours();
var mm = now.getMinutes();
var ss = now.getSeconds();
var ampm = "";
while (i_format < format.length) {
// Get next token from format string
c = format.charAt(i_format);
token = "";
while ((format.charAt(i_format) == c) && (i_format < format.length)) {
token += format.charAt(i_format);
i_format++;
// Extract contents of value based on format token
if (token=="yyyy" || token=="yy" || token=="y") {
if (token=="yyyy") { x=4;y=4; }// 4-digit year
if (token=="yy") { x=2;y=2; }// 2-digit year
if (token=="y") { x=2;y=4; }// 2-or-4-digit year
year = _getInt(val,i_val,x,y);
if (year == null) { return 0; }
i_val += year.length;
if (year.length == 2) {
if (year > 70) {
year = 1900+(year-0);
else {
year = 2000+(year-0);
else if (token=="MMM"){// Month name
month = 0;
for (var i=0; i<MONTH_NAMES.length; i++) {
var month_name = MONTH_NAMES;
if (val.substring(i_val,i_val+month_name.length).toLowerCase() == month_name.toLowerCase()) {
month = i+1;
if (month>12) { month -= 12; }
i_val += month_name.length;
break;
if (month == 0) { return 0; }
if ((month < 1) || (month>12)) { return 0; }
// TODO: Process Month Name
else if (token=="MM" || token=="M") {
x=token.length; y=2;
month = getInt(val,ival,x,y);
if (month == null) { return 0; }
if ((month < 1) || (month > 12)) { return 0; }
i_val += month.length;
else if (token=="dd" || token=="d") {
x=token.length; y=2;
date = getInt(val,ival,x,y);
if (date == null) { return 0; }
if ((date < 1) || (date>31)) { return 0; }
i_val += date.length;
else if (token=="hh" || token=="h") {
x=token.length; y=2;
hh = getInt(val,ival,x,y);
if (hh == null) { return 0; }
if ((hh < 1) || (hh > 12)) { return 0; }
i_val += hh.length;
hh--;
else if (token=="HH" || token=="H") {
x=token.length; y=2;
hh = getInt(val,ival,x,y);
if (hh == null) { return 0; }
if ((hh < 0) || (hh > 23)) { return 0; }
i_val += hh.length;
else if (token=="KK" || token=="K") {
x=token.length; y=2;
hh = getInt(val,ival,x,y);
if (hh == null) { return 0; }
if ((hh < 0) || (hh > 11)) { return 0; }
i_val += hh.length;
else if (token=="kk" || token=="k") {
x=token.length; y=2;
hh = getInt(val,ival,x,y);
if (hh == null) { return 0; }
if ((hh < 1) || (hh > 24)) { return 0; }
i_val += hh.length;
h--;
else if (token=="mm" || token=="m") {
x=token.length; y=2;
mm = getInt(val,ival,x,y);
if (mm == null) { return 0; }
if ((mm < 0) || (mm > 59)) { return 0; }
i_val += mm.length;
else if (token=="ss" || token=="s") {
x=token.length; y=2;
ss = getInt(val,ival,x,y);
if (ss == null) { return 0; }
if ((ss < 0) || (ss > 59)) { return 0; }
i_val += ss.length;
else if (token=="a") {
if (val.substring(i_val,i_val+2).toLowerCase() == "am") {
ampm = "AM";
else if (val.substring(i_val,i_val+2).toLowerCase() == "pm") {
ampm = "PM";
else {
return 0;
else {
if (val.substring(i_val,i_val+token.length) != token) {
return 0;
else {
i_val += token.length;
// If there are any trailing characters left in the value, it doesn't match
if (i_val != val.length) {
return 0;
// Is date valid for month?
if (month == 2) {
// Check for leap year
if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) { // leap year
if (date > 29){ return false; }
else {
if (date > 28) { return false; }
if ((month==4)||(month==6)||(month==9)||(month==11)) {
if (date > 30) { return false; }
// Correct hours value
if (hh<12 && ampm=="PM") {
hh+=12;
else if (hh>11 && ampm=="AM") {
hh-=12;
var newdate = new Date(year,month-1,date,hh,mm,ss);
return newdate.getTime();
Hope this helps
Regards
Rohit
Similar Messages
-
How to validate date formate YYYY-MM-DDThh:mm:ss ?
i have implemented validation for YYYY-MM-DD <br>
but how to validate for time <br>
here is the code for date validation
could you please anyone help me on this issue
<br><br><br> public static boolean validateDateFormate(String date) <br><br>
{ <br>
<br> try { <br>
<br> String dateFormat="yyyy-MM-ddYYYY-MM-DDThh:mm:ss";
<br> String temp = date.substring(0,date.indexOf("-"));
<br> if(temp.length()!= 4)
<br> return false;
<br> SimpleDateFormat df=new SimpleDateFormat(dateFormat);
<br> Date date1=df.parse(date);
<br>String resultDateString=df.format(date1);
<br>System.out.println("date1"+resultDateString);
<br> if ( !date.equals(resultDateString)) { return false; }
<br> } catch (Exception de) {
<br> System.out.println(de);
<br> return false;
<br>
<br>}
<br> return true;
<br> }A useful Data util class
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;
public final class SlacDate implements Comparable
public final static int FormatDDMMCCYY = 0;
public final static int FormatMMDDCCYY = 1;
public final static int FormatDATETIME = 2;
public final static int FormatMMMDDTIME = 3;
public final static int FormatTIMESTAMP = 4;
public final static int FormatCCYYMMDD = 5;
public final static int FormatCCYYMMDDHHMM = 6;
public final static int FormatCCYYMMDDHHMMSS = 7;
public final static int FormatDDMMCCYYTIME = 8;
public final static int FormatDATEVERBOSE = 9;
public final static int FormatDATETIMEVERBOSE = 10;
public final static int FormatHHMMSS = 11;
public final static int FormatHHMMSSMIL = 12;
public final static int FormatDB2TIMESTAMP = 13;
public final static int FormatUDBTIMESTAMP = 14;
public final static int JANUARY = 1;
public final static int FEBRUARY = 2;
public final static int MARCH = 3;
public final static int APRIL = 4;
public final static int MAY = 5;
public final static int JUNE = 6;
public final static int JULY = 7;
public final static int AUGUST = 8;
public final static int SEPTEMBER = 9;
public final static int OCTOBER = 10;
public final static int NOVEMBER = 11;
public final static int DECEMBER = 12;
public final static int MONTHS_IN_YEAR = 12;
public final static int SUNDAY = 1;
public final static int MONDAY = 2;
public final static int TUESDAY = 3;
public final static int WEDNESDAY = 4;
public final static int THURSDAY = 5;
public final static int FRIDAY = 6;
public final static int SATURDAY = 7;
public final static int DAYS_IN_WEEK = 7;
private final static int DefaultHours = 12;
private final static int DefaultMinutes = 0;
private final static int DefaultSeconds = 0;
private final static int DefaultMillis = 0;
private final static int DaysInMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
private final static String MonthAbbrev[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
private final static String MonthVerbose[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
private final static String DaysOfWeekAbbrev[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
private final static String DaysOfWeek[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
private final static String DayExtension[] = { "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" };
private final static String EMPTY = "";
private final static String COLON = ":";
private final static String PERIOD = ".";
private final static String HYPHEN = "-";
private final static String SPACE = " ";
private final static String ZERO = "0";
private static String s_dateSep = HYPHEN;
private int m_dd, m_mm, m_yyyy, m_hh, m_min, m_ss, m_mil;
private static long MillisInSecond = 1000;
private static long MillisInMinute = MillisInSecond * 60;
private static long MillisInHour = MillisInMinute * 60;
private static long MillisInDay = MillisInHour * 24;
* JDK_BST_FIX
* Static initialisation block - check JDK vendor/version in order to determine whether
* an adjustment to correctly report British summertime needs to be made. This is required
* in order to fix a bug in some Sun & IBM JDKs. If an untested version of the Sun or IBM JDK
* is used, we log an error message warning that this block of code should be examained and
* changed as appropriate. This is ugly, but will prevent a new JDK being used and this bug
* creeping back in.
* Note the following JDKs have been tested under both NT & AIX
* JDK Version NT AIX
* 1.1.7 (IBM) x x
* 1.1.7A (IBM) ?
* 1.1.7B (IBM) ? ?
* 1.1.8 (IBM) x x
* 1.2.2 (IBM) ok ok
* 1.1.7 (SUN) x x
* 1.1.8 (SUN) x x
* 1.2 (SUN) x x
private final static String SunVendorString = "Sun Microsystems Inc.";
private final static String IBMVendorString = "IBM"; // Can also be 'IBM Corporation'
private final static String SunProblemJDKs[] = { "1.1.4", "1.1.5", "1.1.6", "1.1.7", "1.1.7A", "1.1.7B", "1.1.8", "1.2", "1.2.2" };
private final static String SunOKJDKs[] = { "1.0.2", "1.1.2", "1.1.3", "1.4.0", "1.4.2"};
private final static String IBMProblemJDKs[] = { "1.1.4", "1.1.5", "1.1.6", "1.1.7", "1.1.7A", "1.1.8" };
private final static String IBMOKJDKs[] = { "1.0.2", "1.1.2", "1.1.3", "1.1.7B", "1.2.2", "1.3.0", "1.3.1" };
private static boolean s_adjustForBST = false;
static
String vendor = System.getProperty("java.vendor");
String jdk = System.getProperty("java.version");
// Check applies to Sun only.
if (vendor.equals(SunVendorString) || vendor.startsWith(IBMVendorString))
String problemJDKs[] = null;
String OKJDKs[] = null;
if (vendor.equals(SunVendorString))
problemJDKs = SunProblemJDKs;
OKJDKs = SunOKJDKs;
else
problemJDKs = IBMProblemJDKs;
OKJDKs = IBMOKJDKs;
// Determine whether we need to make adjustment
for (int i = 0; i < problemJDKs.length; i++)
if (problemJDKs.equals(jdk))
s_adjustForBST = true;
break;
// If we do not need to make the adjustment then check that the
// JDK reported is one of the versions that we know to be good.
// If it is not log an error message.
if (!s_adjustForBST)
boolean goodJDK = false;
for (int i = 0; i < OKJDKs.length; i++)
if (OKJDKs[i].equals(jdk))
goodJDK = true;
break;
/* CR176 - we now anticipate that all JDKs post 1.3.x are "good" ones
if (!goodJDK)
// We do not use the SingletonLogger mechanism since we
// cannot be sure that these singleton objects have been instantiated
// at this point, and in any case it is not desirable to introduce
// this dependancy into SlacDate.
System.err.println("JDK VERSION ERROR : Unsupported JDK - '" + jdk + "' provided by '" + vendor + "'. SlacDate class requires examination.");
* Construct the date with todays date.
* <p>This should be the only place where a Date object is explicitly instantiated. All
* other code should use SlacDate. If the s_adjustForBST flag is set and the date falls
* between the last sunday of March and the last Sunday of October (inclusive) then we need
* to make an adjustment of +1 hour so that British Summertime is correctly reported.
private SlacDate()
init(Calendar.getInstance());
* Construct the date with the specified day, month and year.
* @param year The year to set the date to
* @param month The month to set the date to
* @param date The date to set the date to
* @exception InvalidDateException Invalid date parameters passed in.
public SlacDate(int year, int month, int date) throws InvalidDateException
init(year, month, date, DefaultHours, DefaultMinutes, DefaultSeconds, DefaultMillis);
* Construct the date with the specified day, month, year, hour and minute.
* @param year The year to set the date to
* @param month The month to set the date to
* @param date The date to set the date to
* @param hr The hour to set the date to
* @param min The minute to set the date to
* @exception InvalidDateException Invalid date parameters passed in.
public SlacDate(int year, int month, int date, int hr, int min) throws InvalidDateException
init(year, month, date, hr, min, DefaultSeconds, DefaultMillis);
* Construct the date with the specified day, month, year, hour, minute and second.
* Will default to 0 milliseconds.
* @param year The year to set the date to
* @param month The month to set the date to
* @param date The date to set the date to
* @param hr The hour to set the date to
* @param min The minute to set the date to
* @param sec The second to set the date to
* @exception InvalidDateException Invalid date parameters passed in.
public SlacDate(int year, int month, int date, int hr, int min, int sec) throws InvalidDateException
init(year, month, date, hr, min, sec, DefaultMillis);
* Construct the date with the specified day, month, year, hour, minute, second and milliseconds.
* @param year The year to set the date to
* @param month The month to set the date to
* @param date The date to set the date to
* @param hr The hour to set the date to
* @param min The minute to set the date to
* @param sec The second to set the date to
* @param millis The milliseconds to set the date to
* @exception InvalidDateException Invalid date parameters passed in.
public SlacDate(int year, int month, int date, int hr, int min, int sec, int millis) throws InvalidDateException
init(year, month, date, hr, min, sec, millis);
* Construct the date from a timestamp.
public SlacDate(long timestamp) throws InvalidDateException
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(timestamp));
init(cal);
* Construct the date from the specified string. Note that the date must
* be in day/month/year format.
* @param date The date string.
* @exception InvalidDateException The date passed in is invalid.
public SlacDate(String date) throws InvalidDateException
init(date);
* Construct the date from the specified string. The format passed in will
* identify the format of the date.
* @param date The date string.
* @param format The format of the date.
* @exception InvalidDateException The date passed in is invalid.
public SlacDate(String date, int format) throws InvalidDateException
if (format == FormatCCYYMMDD || format == FormatCCYYMMDDHHMM || format == FormatCCYYMMDDHHMMSS)
boolean valid = false;
date = date.trim();
if (date.length() >= 8)
try
int year = Integer.parseInt(date.substring(0,4));
int month = Integer.parseInt(date.substring(4,6));
int day = Integer.parseInt(date.substring(6,8));
int hour;
int min;
int sec;
if (date.length() > 8)
hour = Integer.parseInt(date.substring(8,10));
min = Integer.parseInt(date.substring(10,12));
if (date.length() >= 14)
sec = Integer.parseInt(date.substring(12,14));
else
sec = DefaultSeconds;
else
hour = DefaultHours;
min = DefaultMinutes;
sec = DefaultSeconds;
init(year, month, day, hour, min, sec, DefaultMillis);
valid = true;
catch (Exception e)
if (!valid)
throw new InvalidDateException("Invalid date: " + date + " for the specified format");
else if (format == FormatDB2TIMESTAMP || format == FormatUDBTIMESTAMP)
// 2002-02-04 10:49:30.999000 (UDB)
// 2002-02-04-10.49.30.999000 (DB2)
int year = Integer.parseInt(date.substring(0,4));
int month = Integer.parseInt(date.substring(5,7));
int day = Integer.parseInt(date.substring(8,10));
int hour = Integer.parseInt(date.substring(11,13));
int min = Integer.parseInt(date.substring(14,16));
int sec = Integer.parseInt(date.substring(17,19));
int millis = Integer.parseInt(date.substring(20,23));
init(year, month, day, hour, min, sec, millis);
else
init(date);
* Construct the date with the java.util.Date passed in.
public SlacDate(Date date)
init(date);
* Init the date with the java.util.Date passed in.
private void init(Date date)
Calendar cal = Calendar.getInstance();
cal.setTime(date);
init(cal);
* Return whether this date is after the date passed in.
* @d2 The date to compare against.
* @return Whether this date is after the date passed in.
public boolean after(SlacDate d2)
int xx = d2.getYear();
if (m_yyyy > xx)
return true;
else if (m_yyyy < xx)
return false;
else
xx = d2.getMonth();
if (m_mm > xx)
return true;
else if (m_mm < xx)
return false;
else
xx = d2.getDate();
if (m_dd > xx)
return true;
else if (m_dd < xx)
return false;
else
xx = d2.getHour();
if (m_hh > xx)
return true;
else if (m_hh < xx)
return false;
else
xx = d2.getMinute();
if (m_min > xx)
return true;
else if (m_min < xx)
return false;
else
xx = d2.getSecond();
if (m_ss > xx)
return true;
else if (m_ss < xx)
return false;
else
return (m_mil > d2.getMillisecond());
private void appendHoursMinutes(StringBuffer str, String separator)
if (m_hh < 10)
str.append(ZERO);
str.append(Integer.toString(m_hh));
if (!separator.equals(EMPTY))
str.append(separator);
if (m_min < 10)
str.append(ZERO);
str.append(Integer.toString(m_min));
private void appendTime(StringBuffer str, String separator, boolean addMillis)
appendHoursMinutes(str, separator);
if (!separator.equals(EMPTY))
str.append(separator);
if (m_ss < 10)
str.append(ZERO);
str.append(Integer.toString(m_ss));
if (addMillis)
if (!separator.equals(EMPTY))
str.append(separator);
if (m_mil < 100)
str.append(ZERO);
if (m_mil < 10)
str.append(ZERO);
str.append(m_mil);
* Version of the asString() method which defaults to FormatDDMMCCYY.
* <p>An example date in this format is:
* <pre>
* 25-02-1999
* </pre>
* @return The Date as a string in DDMMCCYY format.
public String asString()
return asString(FormatDDMMCCYY);
* Convert the date to a String. This will format the Date as defined by the format
* passed in. The default parameter is FormatDDMMCCYY.
* The valid formats are:
* <ul>
* <li>FormatDDMMCCYY</li>
* <li>FormatMMDDCCYY</li>
* <li>FormatDATETIME</li>
* <li>FormatDDMMTIME</li>
* <li>FormatTIMESTAMP</li>
* <li>FormatCCYYMMDD</li>
* <li>FormatCCYYMMDDHHMM</li>
* <li>FormatCCYYMMDDHHMMSS</li>
* <li>FormatDDMMCCYYTIME</li>
* <li>FormatDATEVERBOSE</li>
* <li>FormatDATETIMEVERBOSE</li>
* <li>FormatHHMMSS</li>
* <li>FormatHHMMSSMIL</li>
* <li>FormatDB2TIMESTAMP</li>
* <li>FormatUDBTIMESTAMP</li>
* </ul>
* @param format The format to return the string in.
* @return The date in string format (as specified by the format parameter).
public String asString(int format)
StringBuffer str = new StringBuffer(20);
if (format == FormatDB2TIMESTAMP || format == FormatUDBTIMESTAMP)
str.append(Integer.toString(getYear()));
str.append(HYPHEN);
int month = getMonth();
if (month < 10)
str.append(ZERO);
str.append(Integer.toString(month));
str.append(HYPHEN);
int day = getDate();
if (day < 10)
str.append(ZERO);
str.append(Integer.toString(day));
String dateTimeSeparator = new String();
if (format == FormatDB2TIMESTAMP)
dateTimeSeparator = HYPHEN;
else if (format == FormatUDBTIMESTAMP)
dateTimeSeparator = SPACE;
str.append(dateTimeSeparator);
String timeSeparator = new String();
if (format == FormatDB2TIMESTAMP)
timeSeparator = PERIOD;
else if (format == FormatUDBTIMESTAMP)
timeSeparator = COLON;
appendTime(str, timeSeparator, true);
str.append("000");
else if (format == FormatDATETIME || format == FormatMMMDDTIME || format == FormatTIMESTAMP)
str.append(getMonthNameAbbrev());
str.append(SPACE);
if (m_dd < 10)
str.append(ZERO);
str.append(Integer.toString(m_dd));
str.append(SPACE);
appendTime(str, COLON, false);
if (format == FormatDATETIME)
str.append(SPACE);
str.append(Integer.toString(m_yyyy));
else if (format == FormatTIMESTAMP)
str.append(COLON);
str.append(formattedMillis(m_mil));
else if (format == FormatHHMMSS)
appendTime(str, COLON, false);
else if (format == FormatHHMMSSMIL)
appendTime(str, COLON, true);
else if (format == FormatCCYYMMDD || format == FormatCCYYMMDDHHMM || format == FormatCCYYMMDDHHMMSS)
str.append(Integer.toString(m_yyyy));
if (m_mm < 10)
str.append(ZERO);
str.append(Integer.toString(m_mm));
if (m_dd < 10)
str.append(ZERO);
str.append(Integer.toString(m_dd));
if (format == FormatCCYYMMDDHHMMSS)
appendTime(str, EMPTY, false);
else if (format == FormatCCYYMMDDHHMM)
appendHoursMinutes(str, EMPTY);
else if (format == FormatDATEVERBOSE || format == FormatDATETIMEVERBOSE)
str.append(Integer.toString(m_dd));
if (m_dd > 10 && m_dd < 14)
str.append(DayExtension[0]);
else
str.append(DayExtension[m_dd%10]);
str.append(SPACE);
str.append(getMonthName());
str.append(SPACE);
str.append(Integer.toString(m_yyyy));
if (format == FormatDATETIMEVERBOSE)
str.append(",");
str.append(SPACE);
appendTime(str, COLON, false);
else
// DDMMCCYY, MMDDCCYY, DDMMCCYYTIME
int first;
int second;
if (format != FormatMMDDCCYY)
first = getDate();
second = getMonth();
else
second = getDate();
first = getMonth();
if (first < 10)
str.append(ZERO);
str.append(Integer.toString(first));
str.append(s_dateSep);
if (second < 10)
str.append(ZERO);
str.append(Integer.toString(second));
str.append(s_dateSep);
str.append(Integer.toString(getYear()));
if (format == FormatDDMMCCYYTIME)
str.append(SPACE);
appendTime(str, COLON, false);
return str.toString();
* Return whether this date is before the date passed in
* @d2 The date to compare against.
* @return Whether this date is before the date passed in.
public boolean before(SlacDate d2)
return (!after(d2) && !equals(d2));
* Clone the current date.
* @return The cloned SlacDate object
public Object clone()
SlacDate d = new SlacDate();
d.m_dd = m_dd;
d.m_mm = m_mm;
d.m_yyyy = m_yyyy;
d.m_hh = m_hh;
d.m_min = m_min;
d.m_ss = m_ss;
d.m_mil = m_mil;
return d;
* Compare this date with the supplied date.
* Hours, minutes, seconds and milliseconds are taken into consideration.
* Returns:
* -1 this date is before the supplied date.
* 0 this date is equal to the supplied date.
* 1 this date is after the supplied date.
public int compareTo(Object o2)
SlacDate d2 = (SlacDate)o2;
if (equals(d2))
return 0;
if (after(d2))
return 1;
return -1;
* Compare this date with the supplied date.
* Hours, minutes, seconds and milliseconds are NOT taken into consideration.
* Returns:
* -1 this date is before the supplied date.
* 0 this date is equal to the supplied date.
* 1 this date is after the supplied date.
public int compareDate(Object o2)
SlacDate baseDate = (SlacDate)o2;
SlacDate startBaseDate = new SlacDate(baseDate.getCalendar().getTime());
startBaseDate.setHour(0);
startBaseDate.setMinute(0);
startBaseDate.setSecond(0);
startBaseDate.setMillisecond(0);
SlacDate endBaseDate = new SlacDate(baseDate.getCalendar().getTime());
endBaseDate.setHour(23);
endBaseDate.setMinute(59);
endBaseDate.setSecond(59);
endBaseDate.setMillisecond(999);
int compare = 0;
if (before(startBaseDate))
compare = -1;
else if (after(endBaseDate))
compare = 1;
return compare;
* Compare this date with today's date.
* Hours, minutes, seconds and milliseconds are NOT taken into consideration.
* Returns:
* -1 this date is before today.
* 0 this date is equal to today.
* 1 this date is after today.
public int compareToToday()
return compareDate(today());
* Calculate the difference (in days) between the two dates.
* Note the difference may be negative.
* @param from The <i>start</i> date
* @param to The <i>to</i> date
* @return The difference between the dates in days.
public static int daysBetween(SlacDate from, SlacDate to)
int dayFrom;
int monthFrom;
int yrFrom;
int dayTo;
int monthTo;
int yrTo;
int mult = 1;
if (from.after(to))
mult=-1;
dayFrom = to.getDate();
monthFrom = to.getMonth();
yrFrom = to.getYear();
dayTo = from.getDate();
monthTo = from.getMonth();
yrTo = from.getYear();
else
dayFrom = from.getDate();
monthFrom = from.getMonth();
yrFrom = from.getYear();
dayTo = to.getDate();
monthTo = to.getMonth();
yrTo = to.getYear();
int cnt=0;
try
if (yrFrom != yrTo)
// Different Years.
for (int i=yrFrom+1; i<yrTo; i++)
cnt += SlacDate.daysInYear(i);
for (int i=monthFrom+1; i<13; i++)
cnt+=daysInMonth(i, yrFrom);
for (int i=1; i<monthTo; i++)
cnt+=daysInMonth(i, yrTo);
cnt += (daysInMonth(monthFrom, yrFrom)-dayFrom);
cnt += dayTo;
else
if (monthFrom != monthTo)
// Same Year but different months.
for (int i=monthFrom+1; i<monthTo; i++)
cnt+=daysInMonth(i, yrFrom);
cnt += (daysInMonth(monthFrom, yrFrom)-dayFrom);
cnt += dayTo;
else
// Same Year and month.
cnt += (dayTo-dayFrom);
catch (InvalidDateException ide)
// This should never happen
return cnt * mult;
* Calculate the number of days from the specified date.
* Note the difference may be negative.
* @param date The date to calculate from
* @return The diference between the two dates in days (may be negative).
public int daysFrom(SlacDate date)
return daysBetween(date, this);
* Calculates the number of days in a given month in a given year
* copes with century dates!
* @param month The month to determine the day count
* @param year The year the month is in (only relevant for February).
* @exception InvalidDateException Invalid parameters passed in. Ie the month was >= 12
* or the month was < 0.
public static int daysInMonth(int month, int year) throws InvalidDateException
if (month > 12 || month <= 0)
throw new InvalidDateException("Invalid month specified to SlacDate.daysInMonth(): " + month);
// month-1, because DaysInMonth array is 0-based.
return (month == FEBRUARY && isLeapYear(year)) ? 29 : DaysInMonth[month-1];
* Calculates the number of days in a given year.
* @param year The year the month is in (only relevant for February).
public static int daysInYear(int year)
return (isLeapYear(year)) ? 365 : 364;
* Calculate the number of days to the specified date.
* Note the difference may be negative.
* @param date The date to calculate to
* @return The diference between the two dates in days (may be negative).
public int daysTo(SlacDate date)
return daysBetween(this, date);
* Decrement the date by the specified number of years, months and days.
* @param years The number of years to increment by
* @param months The number of months to increment by
* @param days The number of days to increment by
public void decrement(int years, int months, int days)
decrementYears(years);
decrementMonths(months);
decrementDays(days);
* Decrement the date by the specified number of days.
* @param days The number of days to decrement by
public void decrementDays(int days)
incrementDays(days * -1);
* Decrement the date by the specified number of hours.
* @param hours The number of hours to decrement by
public void decrementHours(int hours)
incrementHours(hours * -1);
* Decrement the date by the specified number of milliseconds.
* @param seconds The number of seconds to decrement by
public void decrementMilliseconds(int milliseconds)
incrementMilliseconds(milliseconds * -1);
* Decrement the date by the specified number of minutes.
* @param minutes The number of minutes to decrement by
public void decrementMinutes(int minutes)
incrementMinutes(minutes * -1);
* Decrement the date by the specified number of months.
* @param years The number of months to decrement by
public void decrementMonths(int months)
incrementMonths(months * -1);
* Decrement the date by the specified number of seconds.
* @param seconds The number of seconds to decrement by
public void decrementSeconds(int seconds)
incrementSeconds(seconds * -1);
* Decrement the date by the specified number of years.
* @param years The number of years to decrement by
public void decrementYears(int years)
incrementYears(years * -1);
* Calculate the difference between two dates to the nearest second as a String.
* @param from The start date
* @param to The end date
public static String differenceBetween(SlacDate from, SlacDate to)
SlacDate f, t;
if (from.after(to))
t = from;
f = to;
else
t = to;
f = from;
int secs = 0;
int mins = 0;
int hours = 0;
int days = 0;
int months = 0;
int years = 0;
secs = t.getSecond() - f.getSecond();
mins = t.getMinute() - f.getMinute();
hours = t.getHour() - f.getHour();
days = t.getDate() - f.getDate();
months = t.getMonth() - f.getMonth();
years = t.getYear() - f.getYear();
if (secs < 0)
secs += 60;
mins--;
if (mins < 0)
mins += 60;
hours--;
if (hours < 0)
hours += 24;
days--;
if (days < 0)
try
days += daysInMonth(f.getMonth(), f.getYear());
catch (InvalidDateException ide)
days += 30;
months--;
if (months < 0)
months += 12;
years--;
StringBuffer sb = new StringBuffer();
sb.append(years).append(s_dateSep);
sb.append(months).append(s_dateSep);
sb.append(days).append(SPACE);
sb.append(hours).append(COLON);
sb.append(mins).append(COLON);
sb.append(secs);
return sb.toString();
* Calculate the difference between the date passed in and this date.
* Note that if the date passed in is in the future the difference will be
* negative.
* @param from The date from which to return the difference
* @return The difference from the date passed in in String format
public String differenceFrom(SlacDate from)
return differenceBetween(from, this);
* Calculate the difference between this date and the one passed in.
* Note that if the date passed in is in the past the difference will be
* negative.
* @param to The date to which to return the difference
* @return The difference to the date passed in in String format
public String differenceTo(SlacDate to)
return differenceBetween(this, to);
* Return whether the two dates are the same. This will check right down to the second.
* @param d2 The date to compare against
* @return Whether the dates are the same.
public boolean equals(SlacDate d2)
return ((m_yyyy == d2.m_yyyy) &&
(m_mm == d2.m_mm) &&
(m_dd == d2.m_dd) &&
(m_hh == d2.m_hh) &&
(m_min == d2.m_min) &&
(m_ss == d2.m_ss) &&
(m_mil == d2.m_mil));
public String format(DateFormat df)
Calendar cal = getCalendar();
return df.format(cal.getTime());
private final String formattedMillis(int millis)
String rString = null;
if (millis < 10)
rString = "00" + millis;
else if (millis < 100)
rString = ZERO + millis;
else
rString = EMPTY + millis;
return rString;
public Calendar getCalendar()
Calendar cal = Calendar.getInstance();
cal.set(m_yyyy, m_mm-1, m_dd, m_hh, m_min, m_ss);
cal.set(Calendar.MILLISECOND, m_mil);
return cal;
* Return the Date/Time in CCYYMMDD format.
* <p>An example date in this format is:
* <pre>
* 19990225
* </pre>
* @return The Date as a string in CCYYMMDD format.
public String getCCYYMMDD()
return asString(FormatCCYYMMDD);
* Return the Date/Time in CCYYMMDDHHMM format.
* <p>An example date in this format is:
* <pre>
* 199902251423
* </pre>
* @return The Date as a string in CCYYMMDDHHMM format.
public String getCCYYMMDDHHMM()
return asString(FormatCCYYMMDDHHMM);
* Return the Date/Time in CCYYMMDDHHMMSS format.
* <p>An example date in this format is:
* <pre>
* 19990225142356
* </pre>
* @return The Date as a string in CCYYMMDDHHMMSS format.
public String getCCYYMMDDHHMMSS()
return asString(FormatCCYYMMDDHHMMSS);
public int getDate() { return m_dd; }
* Return the date in DATETIME format.
* <p>An example date in this format is:
* <pre>
* Feb 25 14:21:09 1999
* </pre>
* @return The Date as a string in DATETIME format.
public String getDATETIME()
return asString(FormatDATETIME);
* Return the Date/Time in DATETIMEVERBOSE format.
* <p>An example date in this format is:
* <pre>
* 25th February 1999, 14:21:09
* </pre>
* @return The Date as a string in DATETIMEVERBOSE format.
public String getDATETIMEVERBOSE()
return asString(FormatDATETIMEVERBOSE);
* Return the Date/Time in DATEVERBOSE format.
* <p>An example date in this format is:
* <pre>
* 25th February 1999
* </pre>
* @return The Date as a string in DATEVERBOSE format.
public String getDATEVERBOSE()
return asString(FormatDATEVERBOSE);
* Return the day o -
FM or Way to validate Date format. The date is from TEXT File
Dear All,
I need to validate a date field whether it is in proper format.
The field is coming from TEXT file to Internal table by using FM GUI_UPLOAD.
Can any one give me the FM name or guide me how to do that?
Definitely points will be given for correct solution.
Thanks & Regards,
Neerajtry the function module 'DATE_CHECK_PLAUSIBILITY'
call function 'DATE_CHECK_PLAUSIBILITY'
exporting
date = '23.09.2007'
exceptions
plausibility_check_failed = 1
others = 2.
if sy-subrc <> 0.
write:/ 'Please verify the date'.
exit.
endif. -
I am getting a date it MMDDYY format, want to check if it is in the right format and then change to normal format. is there any FM for this?
point will be rewardedHi,
Check this...
DATA: v_char(6).
v_char = '121706'.
DATA: v_date TYPE sydatum.
v_date+4(2) = v_char(2).
v_date6(2) = v_char2(2).
CONCATENATE '20' v_char+4(2) INTO v_date(4).
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = v_date
EXCEPTIONS
plausibility_check_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE: / 'INvalid date'.
ELSE.
WRITE: / 'Correct date'.
ENDIF.
Thanks,
Naren -
Validate Date and block JavaScript page change
how I can validate date acrobat, can block JavaScript page change, only change with a button?
If you use the "util.scand" method date validation is part of the process. It either returns the number of milliseconds from the Epoch date used by JavaScript for the date time object the null value.
Date Arithmetic has some sample scripts, but you need to keep in mind that Date and Time are not independent and using "new Date()" returns the date and time at the time that line of code is executed and that can cause issues for the computing of dates only.
Are you sure of day count, most differences include the start and end dates in the number of days for the calculation.
Custom calculation for today's date field (format is None):
// get today's date an time
var oToday = new Date();
// set to start of day
oToday.setFullYear(oToday.getFullYear(), oToday.getMonth(), oToday.getDate(), 0, 0, 0, 0)
// set field value
event.value = util.printd("d/mm/yyyy", oToday);
Custom calculation for the difference in days field (format None):
var cEnteredDate = this.getField("EnteredDate").value;
var cToday = this.getField("Today").value;
event.value = "";
if(cEnteredDate != "" && cToday != "") {
// process only if date values not empty
// convert date strings to date time objectat midnight
var oEnteredDate = util.scand("d/mm/yyyy", cEnteredDate );
if (oEnteredDate == null) {
app.alert("Error in processing entered date", 2, 0);
oEnteredDate.setFullYear(oEnteredDate.getFullYear(), oEnteredDate.getMonth(),oEnteredDate.getDate(), 0, 0, 0, 0)
var oToday = util.scand("d/mm/yyyy", cToday);
if(oToday == null) {
app.alert("Error converting today", 2,0);
oToday.setFullYear(oToday.getFullYear(), oToday.getMonth(),oToday.getDate(), 0, 0, 0, 0)
// convert date objects to days
var nEnteredDate = Math.floor(oEnteredDate.getTime() / (1000 * 60 * 60 * 24));
var nToday = Math.floor(oToday.getTime() / (1000 * 60 * 60 * 24));
// compute & format the difference
event.value = util.printf("%,0 1.0f", (nToday - nEnteredDate)); -
How to validate when date format is diff Internally and externally
Hello,
How can I validate the Date format if Internal format and external format is different.
Ex :
* SELECT SINGLE CRTSP
** FROM /SAPSLL/PR
** INTO L_CRTSP
** WHERE CRTSP IN S_CRTSP .
CRTSP (YYYY/DD/MM HHMMSEC) Internal Format
S_CRTSP (YYYY/DD/MM) External format - selection option
I had done following to convert the internal format to external format.
DATA : LV_DT TYPE STRING.
DATA : L_CRTSP TYPE /SAPSLL/CRTSP.
SELECT SINGLE CRTSP
FROM /SAPSLL/PR
INTO L_CRTSP.
MOVE : L_CRTSP TO LV_DT. "(YYYY/DD/MM HHMMSEC)
L_LEN = STRLEN( LV_DT ).
L_DATE = LV_DT+0(8).
I have the date format that i need in L_DATE." (YYYY/DD/MM)
Now how should I validate?
* SELECT SINGLE CRTSP
** FROM /SAPSLL/PR
** INTO L_CRTSP
** WHERE CRTSP IN S_CRTSP .
Please let me know how can I validate or how can I write the select query to validate this field.
There should be some way using Wildcard or some function module...which I am not sure...
Any suggestions will be appreciated!
Regards,
Kittu
Edited by: Kittu on Jan 6, 2009 12:58 PMHello,
Thank you for youe response and I apprecaite the help so far.
This logic work if it is Parameter...When I have select option it is not working as it is not taking the range values...
SELECT GUID_PR "Primary Key as GUID in "RAW" Format
CRTSP "PRODUCT CREATED ON
CHTSP "PRODUCT CHANGED ON
FROM /SAPSLL/PR
INTO TABLE T_PR.
DATA : T_PR1 TYPE TY_PR OCCURS 0 WITH HEADER LINE.
DATA: W_TEST TYPE STRING,
W_LV_LEN TYPE I,
W_LV_LEN1 TYPE I,
W_LV_DATE(20) TYPE C,
W_LV_DATE1(20) TYPE C.
DATA : W_V(8) TYPE C,
S_CT(11) TYPE C.
SORT T_PR BY CRTSP CHTSP.
LOOP AT T_PR INTO WA_PR.
W_TEST = WA_PR-CRTSP.
W_LV_LEN = STRLEN( W_TEST ).
W_LV_DATE = W_TEST+0(8).
** IF WE SELECT ONLY ONE DATE IN SELECT OPTION
s_crtsp VALUE IS - IEQ20040101..bY REMOVING FIRST THRID DIGITS
WE ARE GETTING THE S_CRTSP VALUE IS 20040101 AND THIS LOGIC IS WORKING FINE..
MOVE S_CRTSP TO S_CT.
W_LV_LEN1 = STRLEN( S_CT ).
W_LV_DATE1 = S_CT+3(8).
* IF W_LV_DATE NE S_CRTSP
IF W_LV_DATE NE W_LV_DATE1.
W_FLG = 'X'.
DELETE T_PR INDEX SY-TABIX.
ENDIF.
CLEAR W_FLG.
ENDLOOP.
Can we do anything for this...
ANy suggestions would be apprecaited!
Regards,
Kittu -
How to convert any date format to default US format using javascript???
Hi,
I was trying to convert a date format to default US date format. The date format will vary according to different regions (It can be dd/MM/yyyy or MM/dd/yyyy or yyyy/dd/MM or any). I need to convert it in to MM/dd/yyyy always (US Format). Please give some
solutions for the same.
Warm Regards,
Tony Joyhi
it is not trivial task in common case. We faced with similar issue when tried to localize date times in display templates in Sharepoint 2013 depending on site's locale, which can be done only via javascript. In order to do it you need to add date time locale
information from server side to client side, e.g. by defining global variable. See the following article for details:
Localize datetimes in display templates in Content by search web parts in Sharepoint 2013. I extended OTB global object _spPageContextInfo with new property (as far as I remember this object is also available in Sharepoint 2010):
<script type="text/javascript">
jQuery(function() {
if (typeof (_spPageContextInfo) != "undefined" &&
_spPageContextInfo != null) {
<%
var ci = new CultureInfo(1033);
var cultureSerialized = new JavaScriptSerializer().Serialize(
new
name = ci.Name,
dateTimeFormat = ci.DateTimeFormat,
numberFormat = ci.NumberFormat
%>
_spPageContextInfo.currentCultureSerialized = <%= cultureSerialized %>;
</script>
Having different date time formats for your locale, you may use
Date.localeFormat function from MS Ajax for formatting the date in specific format. If in your case format is predefined you may hardcode it without adding DateTime formats from server side.
Blog - http://sadomovalex.blogspot.com
Dynamic CAML queries via C# - http://camlex.codeplex.com -
Hi,
How i can add date format DD-MON-YYYY in this code
$(function() { $( ".datepicker" ).datepicker({
changeMonth: true, changeYear: true }); });I think it may be something in the ball park of
dateFormat : 'dd-M-yy'http://docs.jquery.com/UI/Datepicker/formatDate
I was also just reading this, which may help
Set Date With Javascript
Scott -
Acrobat 9.3.4 doesn't enforce Date Formating
After we upgraded to Acrobat 9.3.4 from a previous version of 9.3 acrobat doesn't enforce date formating..before in a Text field formated as Date mm/dd/yyyy it would autocompelete if we typed in 9/21 to 9/21/2010.. now it doesn't, we can type any random text in the field and it isn't validated.
Ideas?Just checked, its enabled.. when I say validate I'm referring to Acrobat's internal date format validation, not JavaScript.
For example if you create a text box, goto properties, format tab, format category = date, date options mm/dd/yyyy
now if you type:
"abcdef" in that text box it should say, "Invalid Date/time: please ensure that the date/time exists.
if you type 9/21 it will automatically turn it into 9/21/2010.
After Appling the 9.3.4 update no such validation takes place, any value entered is accepted.. -
How to change the date format?
Hi,
I need to display the data format as(YYYY-MM-DD). But now it displays(2009-1-9)
Here is my code snippet which i used to display the data format as(2009-1-9)
*<INPUT TYPE=TEXT NAME="date_submitted" MAXLENGTH=20 SIZE=10 VALUE="" onBlur= "return dateSubmitted()"> (YYYY-MM-DD)*
*<SCRIPT LANGUAGE="javascript">*
dateSubmitted()
*</SCRIPT>*
function dateSubmitted()
if (document.pgUpdate.date_submitted.value == "")
date = new Date();
month = date.getMonth() + 1
document.pgUpdate.date_submitted.value =
date.getYear() + "-" + month + "-" + date.getDate();
return true;
Can anybody help me how to change the date format?
Thanks in advance!prit123 wrote:
use SimpleDateFormat class. The code is :He posted a Javascript related question, not a Java related question.
Please use forums devoted to Javascript. You're here at a Java/JSP forum.
There are JS forums at webdeveloper.com and dynamicdrive.com. Good luck.
String formatPattern = "yyyy-mm-dd";
SimpleDateFormat sdf = new SimpleDateFormat(formatPattern);
sdf.format(yourdate);yyyy-mm-dd denotes year-minutes-days. Please go read the SimpleDateFormat API as well. -
HI guys
i got two obiee server running in our env . both are identical . on one server when ever we rite any report with date column in it it comes up with dd/mm/yyyy output on another server if we right any report all the date column comes with dd mon yyyy format .. i want both of them should show date like dd mon yyyy format .. i checked all the conf files are both are looking same still not able to figure out where should i change for this to work .
please let me know if you need more info from my end.
Regards,
DevHI Kishore
Thanks for your reply i checked all the things but with no success. do think there could be any other place where i should check .
1. nqsconfig date format
its same for both the two installations
DATE_TIME_DISPLAY_FORMAT = "yyyy/mm/dd hh:mi:ss" ;
DATE_DISPLAY_FORMAT = "yyyy/mm/dd" ;
TIME_DISPLAY_FORMAT = "hh:mi:ss" ;
2. make sure that you didn't save date format in column properties from front-end
Just checked and we havan't saved anything in column properties .. even i created new report as well but still format was same ..
3. Did you mention anything in connection pool settings to set date format.
no we havan't mention anything in connection pool
4. Make sure that you are connecting to same database, and date format set for date is same here and there
yahh both the two installatiosn are connected to same database .. but not sure about "date format set for date is same here and there
" hw i can check this
finally, check this: http://108obiee.blogspot.com/2009/04/changing-date-format-mask-in-javascript.html
no its not on one column .. its to all the date format columns on all the reports .. so i think its not case with me .
please let me know if you need more info
Regards,
Dev -
Date format in Discovere Reports
We have created a workbook with a parameter which is supposed to show up an LOV for a parameter in the MON-RR format. Now this LOV shows up
correctly in the Discoverer Desktop edition as MON-RR format, but when we view
the same in Discoverer Viewer it shows up as DD-MON-RRRR.
Earlier we had got a partial resolution on this issue (TAR 3891425.996), wherein by changing the ICX
profile value in Oracle Applications, we are able to set the date mask to MON-R
R.
But now the above profile applies to all the reports and all the dates show up as MON-RR, whereas we want to continue showing the date in DD-MON-RRRR forma
t in some of the reports.
How can this be achieved ?HI Kishore
Thanks for your reply i checked all the things but with no success. do think there could be any other place where i should check .
1. nqsconfig date format
its same for both the two installations
DATE_TIME_DISPLAY_FORMAT = "yyyy/mm/dd hh:mi:ss" ;
DATE_DISPLAY_FORMAT = "yyyy/mm/dd" ;
TIME_DISPLAY_FORMAT = "hh:mi:ss" ;
2. make sure that you didn't save date format in column properties from front-end
Just checked and we havan't saved anything in column properties .. even i created new report as well but still format was same ..
3. Did you mention anything in connection pool settings to set date format.
no we havan't mention anything in connection pool
4. Make sure that you are connecting to same database, and date format set for date is same here and there
yahh both the two installatiosn are connected to same database .. but not sure about "date format set for date is same here and there
" hw i can check this
finally, check this: http://108obiee.blogspot.com/2009/04/changing-date-format-mask-in-javascript.html
no its not on one column .. its to all the date format columns on all the reports .. so i think its not case with me .
please let me know if you need more info
Regards,
Dev -
Can't see HTML and Custom text format under data format tab in obiee.
Hi,
I want to add a java script to my report but I can't see HTML/Custom text format option under Data Format Tab--->"Treat Text as" menu.
My report is a union report.
For data column and numeric columns i can see custom option available but for text columns it is not visisble.
Any idea why it is not showing and what should be done here.
Any pointers are welcome.
Please help,it is really urgent.
Thank in advance!
Edited by: 810008 on May 18, 2011 10:03 PMHi,
Select text column (varchar column) -> Treat Text as -> custom text format ->Remove @ (default) -> add [html]<script>sometext(‘@’)</script> followed by your javascript
for eg:
[html]<script>buildGoogleChart(‘@’)</script> <head> <script type="text/javascript"> function show_alert() { alert("Hello! I am an alert box!"); } </script> </head> <body> <input type="button" onclick="show_alert()" value="Show alert box" /> </body> </html>
hope helps u.........
cheers,
Aravind -
Hi,
I am facing problem in validation data in FDQM.
When I am trying to validate data,I am getting an error as ' An Error occured.Please verify that SQL Date Format Mask is correct'
The current Date Format in our application is YYYYMMDD.
I did not have this problem earlier in validating data.This problem is occuring now only and also this error is coming for few entities only.
Could any one suggest me on how this can be resolved.
ThanksHi Kelly,
I checked periods in control tables and there are no duplicates.
The Period Date Format Mask is MMM-YYYY where as the SQL Date Format Mask is YYYYMMDD.
These settings are there since the time I created application.Has it got anything to do with database.
Appreciate your quick response
Regards,
Mrudula -
Presentation Variable Date Format
Hi all trying to format a presentation variable in a Narrative view , Is there a way that this can be done using javascript or html that i can paste into narrative view.
i want something like "the date being used is @{indate} for month end"
Also date format needs to be dd.mm.yyyy ... its currenty being displayed as yyyy/mm/dd .. I dont want to add the columns in my report and hide them as there seems to be a performance lag when i do that.
Any ideas .. Java gurus out there.
I have tried @{indate}[dd.mm.yyyy] .. but that dont work.
Cheers
Jenny
Edited by: user5470064 on Aug 18, 2011 9:58 AM
Edited by: user5470064 on Aug 18, 2011 9:59 AMHere you go...
I tried in my machine and its working great..
In Answers--> in Criteria TAB, In the column's fx use below formula...
case when 1=1 then EVALUATE('TO_CHAR(%1,%2)' as varchar(20),date '@{pv_date}{1998-07-05}','dd.mm.yyyy') else "ORE Time Dim"."Mnth Name" end
pv_date is the presentation variable and
For "ORE Time Dim"."Mnth Name" use any varchar datatype column...
Hope it helpful...
Thanks
Ashish Gupta
Maybe you are looking for
-
Red Hat 6.2/8i Minium Requirements
The 8i preinstallation guide talks about setting the kernel, shared memory, and semaphore parameters (SHMMIN, SHMMNI, SHMMAX, etc.). Can't I just leave the default values and just proceed with the install? Did everyone else mess with theirs? I only h
-
Hello, I am trying to find any white paper regarding the benefits of migrating oracle database from windows server 2003 32bit to RedHat linux server 64bit. The current db version on windows is 10.2.0.5.0 The new version on linux will be 11.2.0.3.0 If
-
I am new in XI. I was trying to send the IDOC data into mail using mail adapter. I have imported the CREMAS04 idoc in IR. Made data type messege type , messege interfaces, messege mapping , and interface mapping. I gave created SC , Technical system,
-
Hi, im having issue with some of my icon showing nothing, blanks. I'm not sure who else has this issue or if anyone has resolved it. The PDF opens up just fine some its just annoying. Im running windows 8.1 64bit operating system. thanks
-
Is there a way to get two email widgets working on the n97, that or have the one widget display multiple accounts? I have been using messaging which i love, but it does not put a new email indicator in the corner. Any ideas?