15,886,724 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by PopeDarren (Top 19 by date)
PopeDarren
18-Feb-22 16:35pm
View
You're very welcome!
PopeDarren
24-Aug-16 18:44pm
View
I haven't been on this site in a while... sorry for the late response. You really should start a new question and not reply to another question in order to get a good answer.
Well... again, I'd be making a bunch of assumptions...
Below is a test console project I threw together to test formatting dates in C#. From your other replies on this message, it looks like you're in C# and not SQL. Please note that this is NOT a complete solution. This could cause dates to end up in the wrong format and you won't know until looking at the data later, which is, obviously, not good. For example: 10/11/12 will return a date for all three formats found below (Oct 11 2012, 10th November 2012, 2010 November 12). If at all possible, you'll need much more business logic in order to get this one right... and you'll still probably get junk values. However, IF they're just in the two formats you talked about above (yyyy/MM/dd and dd/MM/yyyy) that makes it much easier. You can take the MM/dd/yyyy format out of the code below and just use the other two. You can also replace the date format arrays with just the single formats if your years are always four digits.
static void Main(string[] args)
{
string one = "12/22/2015";
string two = "22/12/2015";
string three = "2015/12/22";
DateTime dateOne, dateTwo, dateThree;
dateOne = ConvertDate(one);
dateTwo = ConvertDate(two);
dateThree = ConvertDate(three);
if (dateOne == dateTwo)
Console.WriteLine("Dates one and two are equal.");
if (dateOne == dateThree)
Console.WriteLine("Dates one and three are equal.");
if (dateTwo == dateThree)
Console.WriteLine("Dates two and three are equal.");
}
public static DateTime ConvertDate(string inVal)
{
DateTime dateValue;
if (DateTime.TryParseExact(inVal, new string[] { "MM/dd/yyyy", "MM/dd/yy" }, null, DateTimeStyles.None, out dateValue))
{
Console.WriteLine("American Date: {0} to {1}",
inVal, dateValue.ToString());
return dateValue;
}
else
{
if (DateTime.TryParseExact(inVal, new string[] { "dd/MM/yyyy", "dd/MM/yy" }, null, DateTimeStyles.None, out dateValue))
{
Console.WriteLine("Great Britain Date: {0} to {1}",
inVal, dateValue.ToString());
return dateValue;
}
else
{
if (DateTime.TryParseExact(inVal, new string[] { "yyyy/MM/dd", "yy/MM/dd" }, null, DateTimeStyles.None, out dateValue))
{
Console.WriteLine("Japan Date: {0} to {1}",
inVal, dateValue.ToString());
return dateValue;
}
else
{
Console.WriteLine("fail");
throw new Exception("Date does not fit known format.");
}
}
}
}
HTH!
PopeDarren
14-Aug-14 15:00pm
View
What's with the down votes? It solved his problem.
PopeDarren
16-Jul-12 11:48am
View
I'm flattered that you think I could solve more problems, but the truth is that I've just wrestled with this problem before. There are people on here that are far more knowledgeable than me.
PopeDarren
13-Jul-12 12:31pm
View
Whoops! What I said about Option 2 was wrong! You don't have to add the runat="server" attribute, you just need to add a name.
<input type="text" id="datepicker_value" name="datepicker_value" style="border:none; " />
Then in your button click:
Me.update_lbl.Text = Request.Form("datepicker_value")
PopeDarren
13-Jul-12 12:13pm
View
As you know text that is set using JavaScript isn't preserved through full page posts. So if you're set on using JavaScript, you're going to have to do the following:
1. Change the update_lbl to an asp:TextBox.
2. Set the readonly attribute to true.
3. Change the client click code on the button: OnClientClick="setText();"
3. Change your jQuery to this:
function setText() {
$('#<%=update_lbl.ClientID%>').val($('#datepicker_value').val());
}
4. On the server side, in the button click event request the labels text. The text has been set by JavaScript, but we have to make the ViewState know that it needs to be a different value:
Private Sub BTN_confirmation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_confirmation.Click
Me.update_lbl.Text = Request.Form(update_lbl.UniqueID)
End Sub
And that will preserve the value that has been changed in JavaScript through a postback. You'll just have to make that textbox look like a label, which isn't difficult.
(OPTION 2) Of course, it would be much simpler if you could get the date from the datepicker_value input. Then you could cut out all of the client side code, leave your label a label, and do this in your button click event on the server side:
Private Sub BTN_confirmation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_confirmation.Click
Me.update_lbl.Text = Request.Form(datepicker_value.UniqueID)
End Sub
This is much cleaner. It may not be possible, however, because your date picker needs to have the following attribute added: runat="server", and that attribute may cause problems for the rest of the page. Or it might be a third party object and you don't have the option to change it.
Hope that helps!
PopeDarren
13-Jul-12 9:47am
View
Is the button causing a full page post? Or are you using an update panel?
PopeDarren
9-Apr-12 10:02am
View
I've had this problem while I was dynamically loading objects, but you might not have that problem. Can you post code, please?
PopeDarren
9-Mar-12 15:25pm
View
Did you move the rest of your site with the web.config? Are you using IIS? Did you set IIS to look for the "application" in the new directory?
PopeDarren
9-Mar-12 15:17pm
View
Is the debugger sitting on the breakpoint when you run this immediate window command?
PopeDarren
9-Mar-12 12:41pm
View
They may be old issues to Microsoft, but not every IT shop is up to date. OUTPUT remains the safest option in my opinion. But you're probably right, SCOPE_IDENTITY is probably more common.
Excellent point. I will update as you suggest. Thanks again.
PopeDarren
9-Mar-12 12:26pm
View
We established that he wasn't using a stored procedure. I just didn't edit my original answer to remove that part. You're the codeProject guru it looks like! Should I edit my solution to only meet Mr.McCloud's needs? Thanks for your response!
SCOPE_IDENTITY may be more common, but I would prefer to send anyone who may be looking for a way to output a variable down a safer path.
http://social.msdn.microsoft.com/Forums/en/transactsql/thread/f7c8b3ee-1b03-46c6-a446-af87a6a2f5ea
Scope_Identity may be better than @@identity, but it still has problems:
http://connect.microsoft.com/SQLServer/feedback/details/328811/scope-identity-sometimes-returns-incorrect-value
PopeDarren
9-Mar-12 12:04pm
View
Have you stepped through your code? Is it actually getting to the update part of this page? If so, is there an error? Or is it just failing to update? Can you post your cmd.CommandText, please? Put a breakpoint on cmd.ExecuteNonQuery and either do a quick watch on the cmd object to get this, or pull it up in the immediate window using "?cmd.CommandText" and press enter. Not everyone knows what the immediate window is. If you don't, don't worry about it. Do what you know.
PopeDarren
9-Mar-12 11:47am
View
My solution is solution 2 at the bottom below your comments on solution 1. ;) I figured it was missed! Good luck, and good work using entities! Keep it up!
PopeDarren
9-Mar-12 11:39am
View
You have to reference the ID after you savechanges. Put it below the PE.SaveChanges() and put a breakpoint on it. When you hit the breakpoint, mouse over the LoginID and it will show you the value. If that's true, then it's a matter of managing the variable correctly so you have it when you log out.
PopeDarren
9-Mar-12 11:25am
View
Then what is in the querystring? Are you sure that id is being passed? When you are on the page that does the update does the address look like www.someaddress.com/mypage.aspx?id=1234
PopeDarren
18-Jan-12 9:46am
View
How about an idea on how to go about solving it?
PopeDarren
21-Dec-11 10:49am
View
Deleted
Reason for my vote of 5
Perfect if you don't care whether you've already examined the parent object. If you're coming from the export to excel page, however, you will need to use a recursive approach or some other method to make sure you're not doing unnecessary work to an object that should have already been removed from the stream.
PopeDarren
21-Dec-11 10:49am
View
Deleted
Reason for my vote of 5
Perfect if you don't care whether you've already examined the parent object. If you're coming from the export to excel page, however, you will need to use a recursive approach or some other method to make sure you're not doing unnecessary work to an object that should already have been removed from the stream.
Show More