Gridview time format - asp.net

I have a BoundField that's using a Datafield linked to a datetime type variable. I want to display only the time, not the date. How do you show the time in 24-hour format or in AM/PM format, depending on a boolean in the code behind.
Thanks.

Try something like this:
<%# Eval("AmPmMode").ToString().Equals("true")) ?
String.Format("{0:hh}:{0:mm} {tt}", Eval("date")) :
String.Format("{0:HH}:{0:mm}", Eval("date")) %>
You can format your date for AM PM mode or for 24h mode. tt is the AM/PM designator.
AmPmMode is flag from you DB, should be true or false, but you could change it to 0 or 1.
See also:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Related

Convert datepicker date to ISO format with moment.js

My task is to use a datepicker to pick a date in the prescribed format, eg(MM-DD-YYYY) and pass it to the server as ISO formatted.
While it test the output the ISO formatted date is one day behind.
For example
If i select
07-13-2015
My Output ISO format is
ISO format is :2015-07-12T18:30:00.000Z
Here you can see date is 13 but the output date is 12
I am from India. I tried with zone and utcOffset, ended up with no results. How do i set it right
Here is the JSFIDDLE
js code
$('#datetimepicker1').on("dp.change",function(e){
var selectedDate = $('#datetimepicker1').find("input").val();
selectedDate = moment(selectedDate,"MM-DD-YYYY");
$(".temp").text(moment(selectedDate).toISOString());
});
I do have a hidden field which value will be updated on change and that will be processed in the server. No issues on that.
$('#datetimepicker1').on("dp.change",function(e){
var selectedDate = $('#datetimepicker1').find("input").val();
selectedDate = moment(selectedDate,"MM-DD-YYYY");
$(".temp").text(selectedDate.toISOString());
});
Your selectedDate is already a moment object so you do not need to feed it back into another moment.
Example:
var test = '07-13-2015'
var mtest = moment(test,"MM-DD-YYYY")
mtest.toISOString()
"2015-07-13T06:00:00.000Z"
Your could try converting the date format to UTC at once.
selectedDate = moment(selectedDate).utc('MM-DD-YYYY')
According to http://dygraphs.com/date-formats.html, if you pass a string like '07-13-2015', it means Midnight of 13th July 2015. Now, if you use toISOString function, it will convert it to UTC by default. To not convert it to UTC, just pass a parameter true in the toISOString function. (Moment.js docs)
For example:
var date = '07-13-2015';
date = moment(date,'MM-DD-YYY');
console.log(date.toISOString(true));
This way, moment will not convert the date to UTC.

Date text field asp.net

Can anyone lead me in the right direction as to how to set a textbox such as this:
<td><asp:TextBox ID="txtBoxDate" runat="server" CssClass="fields"></asp:TextBox></td>
Into a masked text box that meets this style "mm/dd/yyyy"
Why not just simply convert the DateTime object to that format in server-side code?
Try this
DateTime dateTime = "your-date-time";
var asString = dateTime.ToString("mm/dd/yyyy");
asString will now have the format you've converted the DateTime object to. It will be string. So, after this step you can execute this
txtBoxDate.Text = asString;
..this might be the code you're looking for.

VB6 - "Time-Formatted" Datepicker passes invalid date (below 1/1/1900)

I have a VB6 Datepicker with the following properties:
Format Type - Time
Min Date - 1/1/1900
Value - 12:00:00 AM
And I initialize it like this:
dtpTimeVal = TimeValue("00:00:00")
However, when I get the date value of the time picker, it returns the value 12/30/1899.
Am I missing any properties or initialization logic here?
there probably is some error where you set the format
the following works:
Private Sub Form_Load()
DTPicker1.Format = dtpTime
DTPicker1.Value = "00:00:00"
End Sub
if i remove the format line, then i get the same result as you do

formatting events date and time on fullcalendar

Supposing am getting the dates for an event from a database in what format should my event date be am thinking.
start: 2012-03-29, 08:00am,
end: 2012-03-30, 08:00am,
allday: false,
it does not recognize the end date and the time for the event
Am I doing the wrong thing?
I use the following format and it works for me:
mm/dd/yyyy hh:mm tt
e.g.
03/15/2012 05:10 AM
Also make sure that in your JSon you have allDay as a boolean and not as a string
"allDay"= "false", // this is wrong. In this case you won't see any events on your calendar
"allDay"= false, // This is correct
Hope this helps

how do i validate date input in dd-mon-yyyy format in asp.net regularExpressionValidator?

I really neeed dd-mon-yy format because my oracle database accepts dates in this format.
Can I validate like that in RegularExpressionValidator like that?
And also, do I have to convert the textbox value to oracle data time format, when using nhibernate?
thanks a lot for help;
try
Regx.ValidationExpression=#"^(([1-9])|(0[1-9])|(1[0-2]))\-((0[1-9])
|([1-31]))\-((\d{2})|(\d{4}))$";
or
you can try this custom validator instead
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
DateTime result;
if (!DateTime.TryParse(args.Value, out result))
{
args.IsValid = false;
return;
} else args.IsValid = true;
}
Is it necessary to force the user to enter the data in the format proscribed by the Oracle database? As long as the user enters a valid date, you can parse the input into a DateTime object and then call ToString("dd-MMMM-yy") to produce a representation of the date in the format required by the database. This gives you the freedom to provide more a user-friendly means of collecting input from the user e.g. a date/time picker type control.
For two digits for the year try:
^([012]?\d|3[01])-([Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])-\d\d$
With four digits for the year:
^([012]?\d|3[01])-([Jj][Aa][Nn]|[Ff][Ee][Bb]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][Uu][Ll]|[Aa][Uu][Gg]|[Ss][Ee][Pp]|[Oo][Cc][Tt]|[Nn][Oo][Vv]|[Dd][Ee][Cc])-(19|20)\d\d$
Those expressions mean:
0 or 1 or 2 followed by a number, or 3 plus 0 or 1
next a dash
For the month it 'tries' all the combinations of JAN, JAn, Jan, jan, etc... for all the twelve months
next a dash
Finally it expects two digits for 'yyyy' version or 19 or 20 followed by two digits for 'yy' version

Resources