Autochange a date in .aspx files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • developerquery
    New Member
    • Jun 2012
    • 17

    #1

    Autochange a date in .aspx files

    Daily I have to manually change the date on a index.aspx
    page,then upload it on FTP,what would be the C# code which changes the date automatically on a daily basis,I tried this script:
    Code:
    <script language="JavaScript">
    <!--
    var days=new Array(8);
    days[1] = "Sun";
    days[2] = "Mon";
    days[3] = "Tue";
    days[4] = "Wed";
    days[5] = "Thu";
    days[6] = "Fri";
    days[7] = "Sat";
    var months=new Array(13);
    months[1] = "Jan";
    months[2] = "Feb";
    months[3] = "Mar";
    months[4] = "Apr";
    months[5] = "May";
    months[6] = "Jun";
    months[7] = "Jul";
    months[8] = "Aug";
    months[9] = "Sep";
    months[10] = "Oct";
    months[11] = "Nov";
    months[12] = "Dec";
    var dateObj=new Date()
    var wday=days[dateObj.getDay() + 1]
    var lmonth=months[dateObj.getMonth() + 1]
    var date=dateObj.getDate()
    var year=dateObj.getYear()
    if (year >= 100 && year <= 1999)
    {year=year + 1900}
    else
    {year=year}
    document.write(date+ " " + lmonth + " " + year)
    </script>
    The problem is that it accepts the date of the users machine which is incorrect.
    Last edited by Frinavale; Aug 9 '12, 01:02 PM. Reason: Added code tags
  • ariful alam
    New Member
    • Jan 2011
    • 185

    #2
    If you want to view the server machine date, you have to code it using the language you used in your ASP.net .aspx page (C#.net, VB.net. etc.). JavaScript is able to track the client side information like this. Just a server side scripting language can track this kind of information from the server machine.

    Just convert your JavaScript techniques to ASP.net language code.

    Hope it's work for you. :)

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      You can get the current date in your server-side code using the DateTime.Now static property.

      In JavaScript, if you want the date use the Date Object.

      -Frinny
      Last edited by Frinavale; Aug 9 '12, 01:06 PM.

      Comment

      • developerquery
        New Member
        • Jun 2012
        • 17

        #4
        I have tried your first link, even in that when I change my machines date the changed date is reflected.I have used C# while testing the required output.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          If you want the server's date to be the one that appears on the website, use the .NET DateTime to display it.

          The server code does not care about the client's code...so that leads me to believe that maybe your server's operating system is set to the wrong date/time?

          It may help if you posted your current code so that we can see if it's something your code is doing or something else.

          -Frinny

          Comment

          Working...