Index: branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90
===================================================================
--- branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 5075)
+++ branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 5164)
@@ -90,7 +90,7 @@
       nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 )
 
-      CALL ymds2ju( nyear, nmonth, nday, nn_time0*3600._wp, fjulday )  ! we assume that we start run at 00:00
+      CALL ymds2ju( nyear, nmonth, nday, nn_time0*3600._wp, fjulday )  
       IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < 0.1 / rday )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
-      IF( nn_time0 == 0 ) fjulday = fjulday + 1.                       ! move back to the day at nit000 (and not at nit000 - 1)
+      IF( nn_time0*3600 - ndt05 .lt. 0 ) fjulday = fjulday + 1.                    ! move back to the day at nit000 (and not at nit000 - 1)
 
       nsec1jan000 = 0
@@ -113,17 +113,27 @@
       !compute number of days between last monday and today
       CALL ymds2ju( 1900, 01, 01, 0.0, zjul )  ! compute julian day value of 01.01.1900 (our reference that was a Monday)
-      inbday = NINT(fjulday - zjul)            ! compute nb day between  01.01.1900 and current day
+      inbday = FLOOR(fjulday - zjul)            ! compute nb day between  01.01.1900 and start of current day
       idweek = MOD(inbday, 7)                  ! compute nb day between last monday and current day
+      IF (idweek .lt. 0) idweek=idweek+7       ! Avoid negative values for dates before 01.01.1900
 
       ! number of seconds since the beginning of current year/month/week/day at the middle of the time-step
-      nsec_year  = nday_year * nsecd + nn_time0*3600._wp - ndt05   ! 1 time step before the middle of the first time step
-      nsec_month = nday      * nsecd + nn_time0*3600._wp - ndt05   ! because day will be called at the beginning of step
+      IF (nn_time0*3600-ndt05 .gt. 0) THEN
+         ! 1 timestep before current middle of first time step is still the same day
+         nsec_year  = (nday_year-1) * nsecd + nn_time0*3600._wp - ndt05 
+         nsec_month = (nday-1)      * nsecd + nn_time0*3600._wp - ndt05    
+      ELSE
+         ! 1 time step before the middle of the first time step is the previous day 
+         nsec_year  = nday_year * nsecd + nn_time0*3600._wp - ndt05 
+         nsec_month = nday      * nsecd + nn_time0*3600._wp - ndt05   
+      ENDIF
       nsec_week  = idweek    * nsecd + nn_time0*3600._wp - ndt05
-      nsec_day   =             nsecd + nn_time0*3600._wp - ndt05
+      nsec_day   =             nn_time0*3600._wp - ndt05 
       IF( nsec_day .lt. 0 ) nsec_day = nsec_day + nsecd
-      
+      IF( nsec_week .lt. 0 ) nsec_week = nsec_week + nsecd*7
+
       ! control print
-      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8)')' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
-           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week
+      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)')' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
+           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week, '  &
+           &                   nsec_month:', nsec_month , '  nsec_year:' , nsec_year
 
       ! Up to now, calendar parameters are related to the end of previous run (nit000-1)
@@ -335,4 +345,5 @@
                ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
                ndastp = ndate0        ! ndate0 read in the namelist in dom_nam
+               IF( nn_time0*3600-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
                adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
                ! note this is wrong if time step has changed during run
@@ -341,7 +352,7 @@
             ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
             ndastp = ndate0           ! ndate0 read in the namelist in dom_nam
+            IF( nn_time0*3600-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
             adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
          ENDIF
-         IF( nn_time0 == 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
          IF( ABS(adatrj  - REAL(NINT(adatrj),wp)) < 0.1 / rday )   adatrj = REAL(NINT(adatrj),wp)   ! avoid truncation error
          !
Index: branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90
===================================================================
--- branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 5075)
+++ branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 5164)
@@ -49,5 +49,5 @@
       !!----------------------------------------------------------------------
 
-      IF( nsec_day == NINT(0.5_wp * rdttra(1)) ) THEN      ! start a new day
+      IF( nsec_day == NINT(0.5_wp * rdttra(1))  ) THEN      ! start a new day
          !
          IF( kt == nit000 ) THEN
