Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to count time , if only one day left from db .??

Posted on 2009-05-06
8
Medium Priority
?
340 Views
Last Modified: 2013-11-07
In the below condition , i need to run the time in decreasing order untill the date becomes equal..

5:35:00 left
5:34:30 left

0:29:00 left
       
ElseIf countdate = 1 Then
'                   i need to run the the time , in the decreasing order
'Label1.text =  with time count in decreasing order &"Left "
            End If

currentdate = Date.Now.ToString("MM/dd/yyyy")
            Dim diffdbdate As DateTime = dr.Item("date")
            Dim diffdate As Integer
            diffdate = DateDiff("d", currentdate, diffdbdate)
            Dim countdate As String = Replace(diffdate, "-", "")
            If currentdate > diffdbdate Then
                Label1.text =  countdate & "days Before"
            ElseIf countdate = 1 Then
                   i need to run the the time , in the decreasing order
            End If

Open in new window

0
Comment
Question by:Rajar Ahmed
  • 4
  • 4
8 Comments
 
LVL 9

Expert Comment

by:Deathrace
ID: 24313645
Timespan helps you to do that... try this..

TimeSpan tsRemaining = EndDate - DateTime.Now;
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24313841
time count was not decreasing, it actually displayed like this
 1.00:00:00 Left
 
 this is d code , i did...
ElseIf countdate = 1 Then
 Dim tsRemaining As TimeSpan = diffdbdate - currentdate
                 label1.text =tsRemaining.ToString() & "Left"
              End If
<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
0
 
LVL 9

Expert Comment

by:Deathrace
ID: 24314002
Basically timespan, if it is executed continously with some set of interval,, you get the effect of decreasing time...if you use AJAX extension , use timer control , and start the timer in

ElseIf countdate = 1 Then
        Timer1.Interval = 1000
         Timer1.Enabled=true
  End If

protected void Timer1_Tick(object sender, EventArgs e)
    {
          Dim tsRemaining As TimeSpan = diffdbdate - currentdate
                label1.text =tsRemaining.ToString() & "Left"
    }

Open in new window

0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24314194
nope , its a complete dotnet application ,
ajax extension cant be used .......:(...
<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
0
 
LVL 9

Expert Comment

by:Deathrace
ID: 24314314
, go a head for Javascript function which does this use setTimeout for call the function recursively,
below url shows how to find the Timespan but u need to run the code in using setTimeout method.

How to calculate Timespace ?
http://stackoverflow.com/questions/141136/calculate-timespan-in-javascript

finally call the javascript method from server side....using ClientScirptBlock, here is some idea how can u call a javascript funtion from server side...
http://www.codeguru.com/csharp/.net/net_asp/scripting/article.php/c5337
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24314994
did u mean this js...it jus calculate the time difference of two dates in millisecond......

hw can it be done as time count ......?



<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">
<script type="text/javascript">
                function stringToDate(string) {
                        var matches;
                    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2}) (\d{2,2}):(\d{2,2}):(\d{2,2})$/)) {
                       return new Date(matches[1], matches[2] - 1, matches[3], matches[4], matches[5], matches[6]);
                    } else {
                       return null;
                    };
                }
 
                //Convert duration from milliseconds to 0000:00:00.00 format
                function MillisecondsToDuration(n) {
                        var hms = "";
                        var dtm = new Date();
                        dtm.setTime(n);
                        var h = "000" + Math.floor(n / 3600000);
                        var m = "0" + dtm.getMinutes();
                        var s = "0" + dtm.getSeconds();
                        var cs = "0" + Math.round(dtm.getMilliseconds() / 10);
                        hms = h.substr(h.length-4) + ":" + m.substr(m.length-2) + ":";
                        hms += s.substr(s.length-2) + "." + cs.substr(cs.length-2);
                        return hms;
                }
 
                var beginDate = stringToDate('2008-09-19 07:14:00');
                var endDate = stringToDate('2008-09-19 17:35:00');
 
                var n = endDate.getTime() - beginDate.getTime();
 
                alert(MillisecondsToDuration(n));
        </script>

Open in new window

0
 
LVL 9

Accepted Solution

by:
Deathrace earned 1500 total points
ID: 24317266
Hi,
Its really hard right...ok i can point to a user control which does everything for us. Add the control to your toolbox, and follow simple instruction to get remaining time.
There is a good sample for better understanding....

Remember: This uses the timespan as we discussed above..i think you can deduce a timespace with two dates.
http://www.codeproject.com/KB/custom-controls/dhtml_timer.aspx
0
 
LVL 18

Author Comment

by:Rajar Ahmed
ID: 24322715
This url did eveything ,

http://www.hashemian.com/tools/javascript-countdown.htm
<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

Thx for ur suggestions....
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question